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;
}
{
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;
}
No comments :
Post a Comment