SharePoint PowerShell create list from template
In this SharePoint tutorial, we will discuss about SharePoint list templates and SharePoint list template ids. We will cover here:
Microsoft provides various SharePoint list templates that we can use to create various types of lists or libraries.
Complete SharePoint Training Course Bundle for $199 (Just for Today) SharePoint developers or administrators uses SharePoint list template id to create list programmatically. SharePoint list template ids and List template typesYou can see the SharePoint list template ids and SharePoint list templates types from MSDN. These list template id we can use while creating a SharePoint list programmatically. We do not need to remember these list template ids while creating a list or library using the browser.
Let us see how to access SharePoint list template gallery url directly from the browser itself. Every SharePoint site collection has a list template gallery that you can access like below: https://We can use SharePoint list template id 850 to create Page Library in SharePoint 2013/2016/2019 or in SharePoint Online. The template name is PageLibrary. The SharePoint list template id 851 is used to create SharePoint Asset Library. And, the template name is AssetLibrary. The SharePoint list template id 101 is used for creating a document library. And the list template name is DocumentLibrary. The SharePoint list template id 171, we can use to create Tasks with Timeline and Hierarchy and the template name is TasksWithTimelineAndHierarchy. The SharePoint list template id 3100 is for AccessApp. The SharePoint task list template id is 107, we can use list template id 107 to create a tasks list in SharePoint Online or SharePoint 2013/2016/2019. All the above list template ids will work for SharePoint Online also. In SharePoint classic team sites, we can manage list templates, like we can save list as a template and use the SharePoint list template to create new lists. I have written a complete blog post on Save list as a template in SharePoint 2013/2016/Online. Let us see how to get SharePoint list templates using PowerShell. This code will work in SharePoint on-premises versions like SharePoint 2013, SharePoint 2016 or in SharePoint 2019. Below is the PowerShell command to get list templates in SharePoint 2013/2016/2019. You can write the PowerShell script using Visual Studio Code or Windows PowerShell ISE. The below PowerShell Cmdlets displays the list template name, type, description etc. Add-PSSnapin "Microsoft.SharePoint.PowerShell" $SPWeb = Get-SPWeb "http://win-pfcp2dgt8di/sites/EnjoySharePoint/" $SPWeb.ListTemplates | Select Name, type, type_client, Description $SPWeb.dispose()It will display all the list templates like below: This is how, we can get all SharePoint list templates using PowerShell. Let us see, how to get SharePoint list template id and SharePoint list template type of a particular list in SharePoint 2013/2016/Online. This will work for classic SharePoint sites, not in SharePoint modern sites. If you want to see the SharePoint list template used for a list then there is a very easy way to know that from the browser itself. Ok to know this, Open the SharePoint list All Items view and then Right-click on the browser and click on View Source in IE (or View page source in Google Chrome). Then search for “tx.listTemplate“, you will able to see something like: ctx.listTemplate = 100; based on the template used.The value is different for differ different types like for GenericList (CustomList) is 100, for a document library, it is 101, for Survey it is 102, etc. There also you will be able to see list base type like below: ctx.listBaseType=0;You can see the whole list of SharePoint list base types and list template types in this Microsoft URL. Apart from that, you will also be able to see the SharePoint Site title, View name, view title, list name, list title, display form URL, new form URL, edit form URL etc. So this will help you know lots of valuable information from the browser view source itself. This is how we can get SharePoint list template id. Now, let us see how to get SharePoint list templates using JavaScript object model (jsom) in SharePoint. Here we will create an HTML dropdown and then using JSOM (JavaScript object model) we will bind the list templates. HTML code to create dropdown list Here we are creating an HTML dropdown list and are not adding options as we need to bind the dropdown on page load at run time from JSOM web property. Below is HTML code to create the drop down as per the above requirement.
SP namespace template property: The following property is used to gets a value, that specifies the list server template. .get_listTemplateTypeKind()The following property is used to get the template name. .get_name()JSOM code to bind list template (values and name) to drop-down list: By using following JSOM code we bind list templates to a drop-down list. $(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(retrieveListTemplate, "sp.js"); }); var templateCol; function retrieveListTemplate() { var clientContext = new SP.ClientContext.get_current(); var web=clientContext.get_web(); templateCol=web.get_listTemplates(); clientContext.load(templateCol); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } function onQuerySucceeded(sender, args) { var templateEnumerator=templateCol.getEnumerator(); var option = ''; while (templateEnumerator.moveNext()) { var otemplate=templateEnumerator.get_current(); option+='';+''; } $("#ddltemplate").append(option); } function onQueryFailed(sender, args) { alert('Error: '+args.get_message() +'\n'+args.get_stackTrace()); }This is how we can get SharePoint list templates using JavaScript and bind into a dropdown list. If you want to use SharePoint script editor web part, then you can use the below code:
You may like follow SharePoint tutorials: In this tutorial, we learned on SharePoint list templates.
Bhawana Rathore is a Microsoft MVP (3 times in Office Apps & Services) and a passionate SharePoint Consultant, having around 10 years of IT experience in the industry, as well as in .Net technologies. She likes to share her technical expertise in EnjoySharePoint.com and SPGuides.com |