Create list from list template sharepoint 2010 programmatically

Follow Us :

Block of Code snippets that you may wanna use while working with SharePoint list templates

Creating a list using existing Custom List template –

_web.Lists.Add(“MyCustomList”, “My list description”, _siteCollection.GetCustomListTemplates(_web)[“ListTemplateName”]);


SPSite siteCollection = SPContext.Current.Site;
SPWeb _web= SPContext.Current.Web;
SPListTemplateCollection listTemplates = siteCollection.GetCustomListTemplates(_web);
SPListTemplate listTemplate = listTemplates[“ListTemplateName”];

mySite.Lists.Add(“Custom List”, “A list created from a custom list template in the list template catalog”, listTemplate);

_web – > SPweb object
siteCollection -> site collection or SPSite object
ListTemplateName -> Name of your Custom List Template

Creating a list using Out-of-Box List template –

_web.Lists.Add(“MyCustomList”, “My list description”, SPListTemplateType.GenericList);

Programmatically saving a List as a Template in SharePoint 2010 –

SPList mySourcelist = _web.Lists[“MyCustomlist”];
mySourcelist.SaveAsTemplate(“listTemplatename.stp”,”MyListTemplate”, “My List Template Desc”, false);

Tags: SharePoint 2010