Create list from list template sharepoint 2010 programmatically

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"]);

or

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);
mySourcelist.Update();

Speak Your Mind

*

Disclaimer: The contents of this site are provided “AS IS”. Information and views expressed including URL(s) and other Internet website references, may change without notice. You bear the risk of using it. SharePoint, MOSS, SharePoint 2010, SharePoint 2013 and Microsoft are trademarks of the Microsoft Corporation.Learning SharePoint only provides Tips,Tricks and Tutorials for using Microsoft SharePoint, Microsoft Office and related Softwares.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.