Hi All,
In a following post we will see how to create List Template Programmatically.
The below code snippet is applicable to SharePoint 2010 and SharePoint 2013.I feel the code is self explanatory.
In a following post we will see how to create List Template Programmatically.
The below code snippet is applicable to SharePoint 2010 and SharePoint 2013.I feel the code is self explanatory.
public void CreateListTemplate() { try { using (SPSite _oSite = new SPSite("http://abcxyz:7500")) { using (SPWeb _oWeb = _oSite.OpenWeb()) { SPList _oList = _oWeb.Lists.TryGetList("TestList"); if (_oList != null) { string fileName = "TempList"; string name = "TempList"; string description = "This is the List Template"; bool isTempExisted = false; // Get the list instance from the List Template Gallery. SPList olist1 = _oWeb.GetCatalog(SPListTemplateType.ListTemplateCatalog); SPListItemCollection _tempListColl = olist1.GetItems(); if (_tempListColl != null) { if (_tempListColl.Count > 0) { foreach (SPListItem temp in _tempListColl) { if (temp.Name.Equals(fileName+".stp")) { isTempExisted = true; } } } } if (isTempExisted) { Console.WriteLine("Template is already existed with this Name..Please choose another one..!!"); } else { //true - to include the data //false - to not include the data _oList.SaveAsTemplate(fileName + ".stp", name, description, true); _oList.Update(); Console.WriteLine("Template Created Successfully"); Console.ReadLine(); } } } } } catch (Exception ex) { //exception handling } }
0 comments:
Post a Comment