Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Create list from list template sharepoint 2010 programmatically

Create list from list template sharepoint 2010 programmatically

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();

No comments:

Post a Comment