LIST TEMPLATES
List templates are predefined layouts available in SharePoint which can be used to create new content quickly and easily .The List templates are maintained within the site collection List template gallery. Sharepoint provides OOTB functionality to create and delete list templates. Below mentioned are ways to Save a list as List Template and deleting a list template from the List Template Gallery programmatically.
Saving a List Template
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSPsite = new SPSite("http://myserver/site"))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
SPList lstSource = oSPWeb.Lists["SourceList"];
lstSource.SaveAsTemplate("FileName.stp", "Name","Description", false);
lstSource.Update();
}
}
}); //end elivated privileges
Deleting a List Template
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSPsite = new SPSite("http://myserver/site"))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
SPList objLstTempGallery = oSPWeb.Lists["List Template Gallery"];
foreach (SPListItem objLstItem inobjLstTempGallery.Items)
{
if (objLstItem.Title == "DEL_LIST_TEMPLATE_NAME")
{
objLstItem.Delete();
objLstTempGallery.Update();
break;
}
}
}
}
}); //end elivated privileges
No comments:
Post a Comment