IntroductionIn SharePoint, the list templates provide re-usability of columns without recreating it on every single site. For e.g. I have created a custom list which name is Project, in a SharePoint site collection with all relevant columns, Now I want this list structure in other site collections, without recreating the list on every single site. Steps to save a list or library as a templateGo to a SharePoint list, then navigate to list settings present under the list tab on the ribbon and then click on List Settings. Click on Save list as Template under Permissions and Management group. Provide template Filename and Template name. If you want to include the content, then select the check box, Click Ok Click OK on the success page. How to download the list templateGo to site setting, Click on List Templates under web Designers and Gallery. Click on Upload Document on the Files tab, then browse your file i.e-Demo.stop You can also save the list template to your site by using PowerShell script, - try{
- Add-Type-Path"..\Microsoft.SharePoint.Client.dll"
- Add-Type-Path"..\Microsoft.SharePoint.Client.Runtime.dll"
- $SiteUrl=Read-Host"EntertheSiteUrl"
- $UserName=Read-Host"Entertheusername"
- $Password=Read-Host-AsSecureStringPassword
- $ctx=New-ObjectMicrosoft.SharePoint.Client.ClientContext($siteUrl)
- $Credentials=New-ObjectMicrosoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Password)
- $ctx.Credentials=$credentials
- $Web=$Ctx.Web
- $site=$Ctx.Site
- $ctx.Load($web)
- $ctx.Load($site)
- $ctx.ExecuteQuery()
- $ListName=Read-Host"EntertheListName"
- $list=$Ctx.Web.lists.GetByTitle($ListName)
- $FileName=Read-Host"EntertheFileName"
- $TemplateName=Read-Host"EntertheTemplateName"
- $list.SaveAsTemplate($FileName,$TemplateName,"listtemplatedescription",$true)
- $ctx.ExecuteQuery()
- Write-Host-ForegroundColorGreen"SuccessfullysavethelistTemplate."
- sleep10
- }catch{
- Write-Host-ForegroundColorRed'Error',':'
- $Error[0].ToString();
- sleep10
- }
Follow the below screenshot and enter the values into the parameters accordingly. Then you can get a successful message. How to upload list template to another siteGo to site setting, Click on List Templates under web Designers and Gallery. Click on Upload Document in the Files tab, Then browse your file i.e-Demo.stp Go to Site contents, Click on New then select App. Now your list added to the site successfully. You can also add the list template to your site by using PowerShell script, - try{
- Add-Type-Path"..\Microsoft.SharePoint.Client.dll"
- Add-Type-Path"..\Microsoft.SharePoint.Client.Runtime.dll"
- $SiteUrl=Read-Host"EntertheSiteUrl"
- $UserName=Read-Host"Entertheusername"
- $Password=Read-Host-AsSecureStringPassword
- $ctx=New-ObjectMicrosoft.SharePoint.Client.ClientContext($siteUrl)
- $Credentials=New-ObjectMicrosoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Password)
- $ctx.Credentials=$credentials
- $Web=$ctx.Web
- $site=$ctx.Site
- $ctx.Load($web)
- $ctx.Load($site)
- $ctx.ExecuteQuery()
- $Template=$site.GetCustomListTemplates($Web)
- $Lists=$ctx.Web.Lists
- $ctx.Load($Lists)
- $ctx.Load($Template)
- $ctx.ExecuteQuery()
- $TemplateName=Read-Host"EntertheTemplateName"
- $ListName=Read-Host"EntertheListName"
- $ListTemplate=$Template|where{
- $_.Name-eq$TemplateName
- }
- $List=$Lists|where{
- $_.Title-eq$ListName
- }
- If($List-eq$Null){
- $ListCreation=New-ObjectMicrosoft.SharePoint.Client.ListCreationInformation
- $ListCreation.Title=$ListName
- $ListCreation.ListTemplate=$ListTemplate
- $List=$Lists.Add($ListCreation)
- $ctx.ExecuteQuery()
- }
- Write-Host-ForegroundColorGreen"SuccessfullyAddthelist."
- sleep10
- }catch{
- Write-Host-ForegroundColorRed'Error',':'
- $Error[0].ToString();
- sleep10
- }
Follow the below screenshot and enter the values for the parameters accordingly. Then you can get a successful message.
|