Converting SharePoint 2007 document library templates for SharePoint 2010

Your ads will be inserted here by

Easy Ads.

Please go to the plugin admin page to set up your ad code.

Following my previous article on Converting SharePoint 2007 list templates for SharePoint 2010, I received a comment last week on how to achieve this with document libraries, and more improtantly, how to do this with content.  It just so happens, I came across this very same scenrio a few months ago!
 
Essentially, the major difference is that instead of there being a single file involved to convert a list template, there are lots of files that need to be packaged back up – ie the binary files.
 
Now be warned, there is a 10 MB limit for exporting a document library with content, so do not reply on this as part of a migration strategy!
 
Here is the PowerShell script:

Your ads will be inserted here by

Easy Ads.

Please go to the plugin admin page to set up your ad code.

#Script:  UpgradeSharePointDocLibs
#Author:  Peter Heydon (www.heyweb.net)
#Date:	  03 June2011
#Purpose: This script will convert a SharePoint 2007 document library template with content to be SharePoint 2010 compatible.
#
#	WARNING: There is a 10MB limit on creating document library templates
#
#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 = "C:\temp\ps\"	#Ensure it has a trailing backslash ('\')
Set-Alias sz ("C:\Program Files\7-Zip\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
 
	#Start-Sleep -s 5
 
	#Replace files
	$manifestFileIn = $extractPath + "\manifest.xml"
	$manifestFileOut = $extractPath + "\manifestOut.xml"
 
	(Get-Content $manifestFileIn | ForEach-Object {$_ -Replace "<ProductVersion>3","<ProductVersion>4"} | Set-Content $manifestFileOut)
 
	#Cleanup files
	Remove-Item $manifestFileIn
	Rename-Item $manifestFileOut $manifestFileIn
 
	#Recompress (MakeCab)
	$cabFolder = $extractPath
	$filesToCab = get-childitem ($cabFolder)
	$itemNoExtension = $item.name.substring(0,$item.name.length-4)
	$NewSTPFileName =  ($RootDir + "output\" + $itemNoExtension  + ".stp")
	$ddfFile = New-Item ($cabFolder + "\~makecab.ddf") -type file
 
	Add-Content $ddfFile ".OPTION EXPLICIT"
	Add-Content $ddfFile (".Set CabinetNameTemplate=" + $itemNoExtension + ".stp")
	Add-Content $ddfFile ".Set Cabinet=on"
	Add-Content $ddfFile ".Set CompressionType=MSZIP"
	Add-Content $ddfFile (".Set DiskDirectory1=" + $cabFolder)
	Add-Content $ddfFile ".Set DiskDirectoryTemplate=CDROM"
 
	foreach ($item in $filesToCab)
	{
		Add-Content $ddfFile ("`"" + $cabFolder + "\" + $item.name + "`"")
	}
 
	mcab /f $ddfFile
 
	#Rename cab, and move to output folder
	Move-Item ($cabFolder + "\" + $itemNoExtension + ".stp" ) ($RootDir + 'output')
 
	foreach ($item in $filesToCab)
	{
		Remove-Item ($cabFolder + "\" + $item.name)
	}
	Remove-Item $ddfFile
	Remove-Item $extractPath
 
	#Move original file to processed folder
	Move-Item $targetFile ($RootDir + 'processed')
 
}

I haven’t tested this since I wrote it in February, and I don’t have a SharePoint 2007 environment handy at the point of this blog post.  Please leave a comment if it works or not. 

Your ads will be inserted here by

Easy Ads.

Please go to the plugin admin page to set up your ad code.

20 thoughts on “Converting SharePoint 2007 document library templates for SharePoint 2010”

  1. Hi Peter,
    Excelent Article.
    i just had some doubts regarding this migration.
    First :
    content of metadata columns (created,modified,modified by. versioning, customs columns) can be same as in SP2007 into SP2010.
    Second:
    my document library is more than 1GB including content of library.
    is it work for it
    Pls revert to me regarding this..
    Regards
    NavazShaik: muhammednavaz@gmail.com

  2. Hi NavazShaik,

    The main problem that you will have is that you cannot export a document library as a template with more than 10MB of content.

    To keep all of your metadata, and for the size of your content you will probably need to look at performing one of the SharePoint upgrade methods.

    Cheers,
    Peter

  3. Hi Peter,
    I have a document library template created from a library which has many custom aspx pages. When I use this script, it replaces “3” with “4” in every single place in manifest.xml, like file names, GUIDs and etc. Is this how manifest.xml supposed to be changed to make it work in SP2010? I thought only ProductVersion value needs to be changed. I will appreciate much if you can give some insight on this.
    Thanks!

    1. Hi Jouet,

      I’ve updated the script so it replaces “3” with “4”

      Sorry for the confusion.

      Cheers,
      Peter

  4. On running the script I am getting the following error:

    Cabinet Maker – Lossless Data Compression Tool

    ERROR: Could not find file: C:\inetpub\temp\input\templatename\manifest.xml

    Can you help me in this regard?

    Thanks!

    1. Hi Ammar,

      Did the manifest file get updated correctly? Can you try executing the makecab command manually to ensure it works with the generated ddf file?

      Cheers,
      Peter

  5. Hi all,
    I’ve try your solution on my PC and import work fine in my web site but…
    When I create a liste from this imported model I do’nt have all th menu (element, list) in the “bandeau” office2010 like.
    So I can’t do anything with it (no new element menu) and can’t manage the list…
    Can you tell me if I’ve ommit something, or if I must use the script on my Sharepoint serveur…
    Thanks.

  6. I tried your script and it worked but all the items in the list now shows my name in the “Created By” column instead of the person who originally created them. Is there anyway to retain the original user names? Thanks

  7. The other day, while I was at work, my sister stole my apple ipad and tested to see if it can survive a thirty foot drop, just so she can be a youtube
    sensation. My apple ipad is now destroyed
    and she has 83 views. I know this is entirely
    off topic but I had to share it with someone!

Comments are closed.