Saturday, 1 October 2011

Saving custom List as a Template and then Creating List from it in SharePoint 2010


Saving List as Template -

Programmatically saving a List as a Template in SharePoint 2010 -

SPList sourceList = _web.Lists["MyCustomlist"];

sourceList.SaveAsTemplate("listTemplateName.stp","MyListTemplate", "My List Template Desc", false);

sourceList.Update();

Creating a List -

SPSite siteCollection = SPContext.Current.Site;

SPWeb web = SPContext.Current.Web;

SPListTemplateCollection listtempcol = web.Site.GetCustomListTemplates(web);

web.Lists.Add("MyCustomList", "This is my list using Custom List Template", listtempcol["MyListTemplate"]);

Ads by Google

No comments:

Post a Comment