Sharepoint 2010 - Sample code to create Subsite using Visual Studio 2010 - visual-studio-2010

I am new to sharepoint development.
I have a requirement to create subsite in sharepoint server with the help of visual studio 2010. I need a code to create a subsite when a user add a new list item in the sharepoint site. I used EventListViewer to call the Add Item event. Please guide me how to work on this issue.
I am sharing the code i used in event receiver
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
try
{
WriteLog("Process started", System.Diagnostics.EventLogEntryType.SuccessAudit );
// Get Properties
string name = properties.ListItem["Title"].ToString();
string description = properties.ListItem["Description"].ToString();
DateTime startDate = (DateTime)properties.ListItem["Start Date"];
DateTime endDate = (DateTime)properties.ListItem["End Date"];
// Create sub site
SPWeb web = properties.OpenSite().AllWebs.Add(name.Replace(" ", string.Empty), name,
description, 0, SPWebTemplate.WebTemplateSTS, false, false);
web.Update();
WriteLog("Process Completed", System.Diagnostics.EventLogEntryType.SuccessAudit);
}
catch (Exception ex)
{
WriteLog("Error:" + ex.Message + " StackTrace --" + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
}
}

Related

ItemEvent in SAP B1 SDK with a SAP form created in Visual Studio 2015

I truly really need your help.
I want to be able to deal with a Click on an Item on my Form which has been created in Visual Studio 2015
this is my Main Methode :
static void Main(string[] args)
{
try
{
Application oApp = null;
if (args.Length < 1)
{
oApp = new Application();
}
else
{
oApp = new Application(args[0]);
}
Menu MyMenu = new Menu();
MyMenu.AddMenuItems();
oApp.RegisterMenuEventHandler(MyMenu.SBO_Application_MenuEvent);
Application.SBO_Application.AppEvent += new SAPbouiCOM._IApplicationEvents_AppEventEventHandler(SBO_Application_AppEvent);
oApp.Run();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
and this code is automatically generated by Visual studio when i creat a new SAP B1 Project.
now i want to add an ItemEvent to handle some klick events on some Forms.
when i add this to the code :
Application.SBO_Application.ItemEvent += new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler(SBO_Application_ItemEvent);
und of course the Methode SBO_Application_ItemEvent then i got a compiler error in this code line that an object reference is requiered for non-static fields...
what did i miss?
I just want to be able to do something when the User clicks on the Grid in my Form.
A Method to add a click event to a grid on a custom user form,
using Visual Studio and SAP BUSINESS ONE STUDIO:
Open the .b1f file in visual studio designer.
an example form:
Click on the Grid you wish to add the event for and navigate to the properties window
Click the lightening symbol to see the events
Double click the space next to your Desired Event
visual studio should then add the code for the event as required, something similar to the below should appear in code:
private void docRowGrid_ClickBefore(object sboObject, SAPbouiCOM.SBOItemEventArg
pVal, ref bool BubbleEvent)
{
}

Integration of Outlook calendar, GSUIT calendar And iCal programatically C#

I have a specific requirement, I have a .Net Application where I have some dates, so I want to create appointments for these dates in Outlook, GSuit and iCal calendar.
Can someone help me to give steps to create these appointments programmatically C#.
I tried to achieve by adding reference Microsoft.Office.interop.outlook and below code. i got this code from Microsoft site but I have difficulty to replace "this". what code should replace "this" in below code.
{
try
{
Outlook.AppointmentItem newAppointment =
(Outlook.AppointmentItem)
this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
newAppointment.Start = DateTime.Now.AddHours(2);
newAppointment.End = DateTime.Now.AddHours(3);
newAppointment.Location = "ConferenceRoom #2345";
newAppointment.Body =
"We will discuss progress on the group project.";
newAppointment.AllDayEvent = false;
newAppointment.Subject = "Group Project";
newAppointment.Recipients.Add("Roger Harui");
Outlook.Recipients sentTo = newAppointment.Recipients;
Outlook.Recipient sentInvite = null;
sentInvite = sentTo.Add("Holly Holt");
sentInvite.Type = (int)Outlook.OlMeetingRecipientType
.olRequired;
sentInvite = sentTo.Add("David Junca ");
sentInvite.Type = (int)Outlook.OlMeetingRecipientType
.olOptional;
sentTo.ResolveAll();
newAppointment.Save();
newAppointment.Display(true);
}
catch (Exception ex)
{
MessageBox.Show("The following error occurred: " + ex.Message);
}```

Testing SharePoint List Workflow from Visual Studio 2010

I am trying to create a custom workflow in Visual Studio 2010 for SharePoint 2010 and have run into a problem. I have figured out how to deploy the workflow to the SharePoint site, but executing it results in an error. However, the error message is completely non-descriptive, so I want to find out if there is a way to execute it from Visual Studio so I can see where it fails, and possibly why.
I'm trying to simply create a new subsite based on a given ListItem.Title information.
How is it you go about debugging?
For reference, here is my code
class CreateSubsite : System.Workflow.ComponentModel.Activity
{
protected override System.Workflow.ComponentModel.ActivityExecutionStatus
Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext)
{
createSite();
return System.Workflow.ComponentModel.ActivityExecutionStatus.Closed;
}
public void createSite()
{
using (SPSite currentSite = SPContext.Current.Site)
{
using (SPWeb currentWeb = SPContext.Current.Web)
{
SPList currentList = SPContext.Current.List;
SPListItem currentListItem = SPContext.Current.ListItem;
WorkflowContext workflow = new WorkflowContext();
SPSite parentSite = new SPSite(workflow.CurrentWebUrl);
SPWeb newSite = currentSite.AllWebs.Add(
currentListItem.Title.Replace(" ", "_"),
currentListItem.Title,
String.Empty, currentWeb.Language, "CI Template", false, false
);
}
}
}
}
Try to remove Using keyword from your code .You should not dispose your SPSite and SPWeb when you use SPContext because disposing of that object might actually break the workflow as it may still need a reference to that object for later use.
just rewrite your code without use using
public void createSite() {
SPSite currentSite = SPContext.Current.Site
SPWeb currentWeb = SPContext.Current.Web
//.... Rest of your code
Hope that help
Regards.

Creating a new site sharepoint 2010 under parent site with my custom template Programatically using visual studio 2010

I have a parent website under which i want to create subsites on the fly using visual studio 2010.
The subsites which i want to create have a common stuructre(in temrs of lists & custom).
So i saved the template in sharepoint 2010,it becomes wsp and goes into soution gallery.
Now how do i use this template say mytemplate.wsp,to create site in visual studio.
i tried this
using (SPSite site = new SPSite ("http://infml01132:5566/sites/VRND " ))
{
using (SPWeb web = site.OpenWeb())
{
SPWebTemplateCollection myTemplates = site.GetCustomWebTemplates(Convert .ToUInt32(web.Locale.LCID));
//SPWebTemplateCollection temlates1 = site.GetCustomWebTemplates(1033);
//SPWebTemplateCollection temlates = site.GetWebTemplates(1033);
//SPCustomWebTemplate
SPWebTemplate subsitetemplate = myTemplates["vrndtmpl" ];
web.Webs.Add("subsite1" , "rnd subsite1" , "subsite description changed" , Convert .ToUInt16(1033), subsitetemplate, false , false );
}
}
But i dont get my template in mytemplates collection.
Thanks
We are using this code to retrieve site template by it's name:
private SPWebTemplate GetSiteTemplate(SPSite site, string templateName, int lcid)
{
foreach (SPWebTemplate webTemplate in site.GetWebTemplates(lcid))
{
if (webTemplate.Name.ToLower().Contains(templateName.ToLower()))
{
return webTemplate;
}
}
return null;
}
It is 100% works.
So, in your case, you should write:
using (SPSite site = new SPSite ("http://infml01132:5566/sites/VRND"))
{
using (SPWeb web = site.OpenWeb())
{
SPWebTemplate subsitetemplate = GetSiteTemplate(site, "vrndtmpl", 1033);
web.Webs.Add("subsite1" , "rnd subsite1" , "subsite description changed" , uint(1033), subsitetemplate, false , false);
}
}
Also, please, ensure, that you have deployed your site template under SiteTemplates directory, and the corresponding webtemp.xml file to <14 hive>\TEMPLATE\1033\XML or deployed it through feature, as described here.

Outlook 2002 C# COM Add-In build with VS2008 does not start

I am facing a curious problem:
I am trying to build a Add-In for Outlook 2002 with Visual Studio 2008 using the shared add-in template.
I want a simple hello world within the OnStartUpComplete method.
That works pefectly on my development machine, but not at all on a clean machine with outlook 2002.
I used the generated setup project to install the add in.
Load behavior changed back from 3 to 2 after starting outlook, but there neither comes an exception nor any other error.
What do I have to do to get the Add-In working on other than the dev machine?
Thanks a lot,
Michael
i believe your are a lockback policy victim.
add a bypass key to registry, then it works. modern office versions or vsto creates the key while installation. the effect is: install a modern office too and the adddin now are also loaded in older office. please take a look
code snippet taken from NetOffice http://netoffice.codeplex.com
public static void RegisterFunction(Type type)
{
try
{
// add codebase value
Assembly thisAssembly = Assembly.GetAssembly(typeof(ExampleClassicAddin));
RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\1.0.0.0");
key.SetValue("CodeBase", thisAssembly.CodeBase);
key.Close();
key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32");
key.SetValue("CodeBase", thisAssembly.CodeBase);
key.Close();
// add bypass key
// http://support.microsoft.com/kb/948461
key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}");
string defaultValue = key.GetValue("") as string;
if (null == defaultValue)
key.SetValue("", "Office .NET Framework Lockback Bypass Key");
key.Close();
// add addin key
Registry.ClassesRoot.CreateSubKey(#"CLSID\{" + type.GUID.ToString().ToUpper() + #"}\Programmable");
Registry.CurrentUser.CreateSubKey(_addinRegistryKey + _prodId);
RegistryKey rk = Registry.CurrentUser.OpenSubKey(_addinRegistryKey + _prodId, true);
rk.SetValue("LoadBehavior", Convert.ToInt32(3));
rk.SetValue("FriendlyName", _addinName);
rk.SetValue("Description", "NetOffice COMAddinExample with classic UI");
rk.Close();
}
catch (Exception ex)
{
string details = string.Format("{1}{1}Details:{1}{1}{0}", ex.Message, Environment.NewLine);
MessageBox.Show("An error occured." + details, "Register " + _addinName, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

Resources