In
SharePoint, you will create a list based on existing list template only.
Normally, every developer should select “GenericList” template as list template to the newly created lists.
Like this way, in my below code I am creating a list based on my custom list
template.
#region List Template String ListTemplateName=”CustomListTemplateName”; String ListName=”CustomListName”; SPListTemplateCollection listTempColl = currentSite.GetCustomListTemplates(currentSite.RootWeb); //checking if the list template exists or not if (IsListTemplateExists(ListTemplateName, listTempColl) == true) { //Creating the custom list using custom list template. SPListTemplate listQuickLinksTemp = listTempColl[ListTemplateName]; CreateList(currentWeb, ListName, "Description of the list", listQuickLinksTemp); } #endregion #region IsListTemplateExists ////// FUNCTION : IsListTemplateExists /// PURPOSE : Checking whether the List exists in the mentioned Web or not /// PARAMETERS : listTempColl -> collection of list templates /// strListTemplateName -> A string containing the list template name /// RETURNS : The result as a boolean /// 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) { //Code } return isListTempExists; } #endregion //
No comments:
Post a Comment