Explore the Experience in SharePoint 2013

Wednesday, October 22, 2014

Create Custom List Programmatically in SharePoint 2013/2010

No comments
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;
}

No comments :

Post a Comment