Requirement:
- I have a custom list template uploaded to the List template gallery of the site
- How can I create a new list whose template is custom list template using SharePoint object model
Sample Code:
Decription: GetCustomListTemplates(…) method of SPSite object gives the collection of the custom lists.SPSite osite = new SPSite(”http://anjalich11:2020″);
SPWeb oweb = osite.OpenWeb();
SPListTemplateCollection listtempcol = oweb.Site.GetCustomListTemplates(oweb);
oweb.Lists.Add(”TestList”, “This is my list “, listtempcol["TestListSTP"]);
SPList olist = oweb.Lists["TestList"];
olist.OnQuickLaunch = true;
olist.Update();
oweb.Dispose();
osite.Dispose();
SPWeb oweb = osite.OpenWeb();
SPListTemplateCollection listtempcol = oweb.Site.GetCustomListTemplates(oweb);
oweb.Lists.Add(”TestList”, “This is my list “, listtempcol["TestListSTP"]);
SPList olist = oweb.Lists["TestList"];
olist.OnQuickLaunch = true;
olist.Update();
oweb.Dispose();
osite.Dispose();
Note:
- ListTemplates property of SPWeb object returns ONLY the OOB list templates ( as a SPListTemplateCollection). It DOES NOT include the custom list templates (which are stored in the List Template gallery on the site.)
Related Articles
No user responded in this post