Reputation: 1
I got a code to create custom SharePoint list using Visual Studio 2010. But where can I place this code in Visual Studio 2010 was not mentioned anywhere. Can somebody help me please? I am really struggling. Here is the code:
using (SPSite oSPsite = new SPSite("http://Web URL"))
{
oSPsite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
oSPWeb.AllowUnsafeUpdates = true;
/* 1. create list from custom ListTemplate present within ListTemplateGalery */
SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb);
SPListTemplate template = lstTemp["custom template name"];
oSPWeb.Lists.Add("List Name", "Description", template);
/* 2. create list from sharepoint list content type (e.g. Links) */
oSPWeb.Lists.Add("List Name", "Description", SPListTemplateType.Links);
oSPWeb.AllowUnsafeUpdates = false;
}
oSPsite.AllowUnsafeUpdates = false;
}
Upvotes: 0
Views: 151
Reputation: 129
This code can be executed from all the places where you can execute code in sharepoint depending on the requirement , here are some
Upvotes: 0
Reputation: 6859
You could put this in a client application (Console, WinForms, WPF). The only restriction would be that the app will only work if it is executed on the SharePoint server. It will not work remotely.
Another way would be to create a SharePoint Feature and include the code in the Feature Receiver. Chapter 3 of Inside Microsoft SharePoint 2010 describes the process of building a Feature and attaching a Feature Receiver.
http://msdn.microsoft.com/en-us/library/ff872401.aspx
Upvotes: 1