Download multiple list templates from SharePoint Template Gallary.

When we are working on migrating SharePoint Custom list to other SharePoint site.We have to save that list as template and restore again to another server.But suppose you are having so many list then ???

So, In this article I am going to help to you to download all SharePoint list template from Template gallery to local drive and in my another article we will work on upload multiple Custom List templates from local drive and create custom list instances.

Here is my scenario, today I have saved multiple list as template to template gallery and now I wanted to download that.Now by using below code you can simply download the all stp files which you created today.

#Function to copy file from SharePoint template gallary to lo drive
Function DownloadStp($SPFolderURL, $localFolderPath)
{
	$SPFolder = $oWeb.GetFolder($SPFolderURL)
	foreach ($File in $SPFolder.Files)
	{
		#By using below if condition you will get all the templates which are created today.
		if($File.TimeCreated -gt ($(Get-Date).AddDays(-1)))
		{
			$Data = $File.OpenBinary()
			$FilePath= Join-Path $localFolderPath $File.Name
			[System.IO.File]::WriteAllBytes($FilePath, $data)
		}
	}
	foreach ($SubFolder in $SPFolder.SubFolders)
	{
		if($SubFolder.Name -ne "Forms")
		{
			DownloadStp $SubFolder $localFolderPath
	    }
	}
}
$oWeb = Get-SPWeb "http://localhost/"
$oLTG =  $oWeb.Lists["List Template Gallery"].RootFolder
$localDrivePath = "C:\PowershellOutput\StpFiles"
#calling DownloadStp function to download stp files to localDrivePath
DownloadStp $oLTG $localDrivePath 
#disposing web object 
$oWeb.Dispose()

In my next article I am going to help you to create SharePoint custom list using multiple template which are saved in you local drive.
PowerShell script to Upload multiple Custom List template and create custom list instances

2 thoughts on “Download multiple list templates from SharePoint Template Gallary.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s