Wednesday, June 8, 2016

How to check if a list template exists or not in SharePoint?

SPListTemplateCollection listColl = currentSite.GetCustomListTemplates(currentSite.RootWeb);

if (IsListTemplateExists(ListTemplateName, listColl )= true)
 {
 
     SPListTemplate listQuickLinksTemp = listColl [ListTemplateName];
     CreateList(currentWeb, ListName, "Description of the list", listQuickLinksTemp);
  }

Sub function:return true or false


public static bool IsListTemplateExists(string strListTemplateName, SPListTemplateCollection listTempColl)
  {
    bool isListTempExists = false;
    try {
      var temp = listTempColl.Cast().FirstOrDefault(x => x.Name.Equals(strListTemplateName));
      if (temp != null)
      isListTempExists = true;
     }
     catch (Exception ex)
     {
     
     }
   return isListTempExists;
  }

No comments:

Post a Comment