Wednesday 29 July 2015

Converting SharePoint 2007 list templates for SharePoint 2010

I’m hot on the heels of a SharePoint 2007 to 2010 migration project.  It had been decided not to upgrade, but to transition all of the content across and try and make better use of the document management features of SharePoint from scratch.

One of the first problems we discovered was for bringing across list libraries.  This was to be a simple task, simply save the list as a template, import into the new environment and it should just work. Unfortunately, I was greeted with an error along the lines of version 3 templates are not supported in this version of the product“.

Searching for the error, I came across the answer in this blog post of Importing SharePoint 2007 list templates (STP) into SharePoint 2010.

Tom’s solution  worked great, but there was no way I could get general users to extract the list template, edit the XML and re-package.  So I wrote this small PowerShell script:


#Script: UpgradeSharePointList#Author: Peter Heydon (www.heyweb.net)#Date: 16 September 2010#Purpose: This script will convert a SharePoint 2007 list template to be SharePoint 2010 compatible.##Credit for defining the conversion process: http://tom-dw.blogspot.com/2010/06/importing-sharepoint-2007-list.html#Credit for calling 7-Zip from Powershell: http://mats.gardstad.se/matscodemix/2009/02/05/calling-7-zip-from-powershell/#Everything else cobbled together from Microsoft TechNet##Requirements:# Three folders: input (SharePoint 2007 list templates)# output (SharePoint 2010 compatible list templates)# processed (SharePoint 2007 list templates that have been processed)# 7z.exe (from 7-Zip installation: http://www.7-zip.org/)# makecab.exe (should be in your WINDOWS installation folder)##WARNINGS: There is zero error handling, so don't expect the script to be gracefull. The script is supplied# 'as is' and should be tested thoroughly before using in a production environment.

### DEFINITIONS$RootDir = "\\server\share\path\" #Ensure it has a trailing backslash ('\')Set-Alias sz ("C:\path\to\7zip\7z.exe")
Set-Alias mcab ("C:\windows\system32\makecab.exe")

# Get list of all STP files$InputDir = get-childitem ($RootDir + "input")

foreach ($item in $InputDir | where {$_.extension -eq ".stp"})
{
$targetFile = ($RootDir + "input\" +$item.name)
$extractPath = $targetFile.substring(0,$targetFile.length-4)

"Processing: " + $targetFile
#Create directory New-Item $extractPath -type directory

#Expand STP File $extractPathOption = ("-o" + $extractPath)
sz x $extractPathOption $targetFile
#Replace files $manifestFileIn = $extractPath + "\manifest.xml" $manifestFileOut = $extractPath + "\manifestOut.xml" (Get-Content $manifestFileIn | Foreach-Object {$_ -replace "<ProductVersion>3</ProductVersion>", "<ProductVersion>4</ProductVersion>"} | Set-Content $manifestFileOut)

#Cleanup files Remove-Item $manifestFileIn Rename-Item $manifestFileOut $manifestFileIn
#Recompress (MakeCab) $itemNoExtension = $item.name.substring(0,$item.name.length-4)
$CabFileName = ($RootDir + "\output\" + $itemNoExtension + ".cab")
$NewSTPFileName = ($RootDir + "\output\" + $itemNoExtension + ".stp")
mcab $manifestFileIn $CabFileName
#Rename cab, and move to output folder Rename-Item $CabFileName $NewSTPFileName Remove-Item $manifestFileIn Remove-Item $extractPath
#Move original file to processed folder Move-Item $targetFile ($RootDir + 'processed')

}

I have a scheduled task now running every 10 minutes during the day that will process all files in the input folder.  The process is simplified, I’m not having to get involved, so everyone is happy!

No comments:

Post a Comment