Thursday, January 20, 2011

Migrating list or library from SharePoint 2007 (MOSS) to SharePoint 2010






There are many situations when you want to migrate data from SharePoint 2007 (MOSS) to SharePoint 2010. Microsoft has provided lot of material on upgrade or migrate to SharePoint 2010. This is the best starting point. I also have written about the steps to upgrade or migrate TFS 2008 team portals to TFS 2010 team portals. Basically I have considered upgrading and migrating from SharePoint 2007 to SharePoint 2010. You can find the blog post here...


But a situation may also arise where you are required to migrate only certain lists or libraries. In this blog post we will see how you can migrate only certain lists or libraries. The approach for migrating SharePoint 2007 lists and libraries is to save them as list templates with content and migrate them to SharePoint 2010 site.


But unfortunately SharePoint 2007 list templates (version 3) are not supported in SharePoint 2010. For this reason, we have to convert SharePoint 2007 list templates to be SharePoint 2010 compatible. For making list templates compatible we can use PowerShell scripts. I have listed down the prerequisites and steps for converting SharePoint 2007 list templates to be compatible with SharePoint 2010.


1 Prerequisites


Since we will be manually converting the list templates, we will require some tools and will have to follow the below steps


1. List templates from SharePoint 2007 lists and libraries,

2. Three folders : Input to store SharePoint 2007 list templates,

3. Output to store SharePoint 2010 compatible list templates,

4. Processed to store SharePoint 2007 list templates that have been processed,

5. 7z.exe to extract the site template files. We can get it from http://www.7-zip.org/


6. Makecab.exe to prepare a cab file. This is already available in WINDOWS\System32 folder


2 PowerShell Script


Now that we have all the prerequisites, we will make use of the PowerShell scripts to modify the site template file and make them ready for SharePoint 2010. Please use the following PowerShell script.



# Set Root Directory
$RootDir = "C:\Migration\" #Ensure it has a trailing backslash ('\')
Set-Alias sz ("C:\path\to\7zip\7z.exe") #7Zip exe path
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')

}


3. Create List or Library


Once the list templates are converted to SharePoint 2010 compatible, we need to upload them in list templates gallery in SharePoint 2010 site collection. Now we can proceed to creating new list or library from these templates.


Special thanks to: Peter Heydon


-Vighnesh Bendre


2 comments:

colinbashbash said...

We're looking at moving from VSS to TFS 2010. We currently have a relatively new Sharepoint 2007 site that will be converted to Sharepoint 2010 early next year, once the company has moved everyone to windows7/office2010.

Ok, so the two ways I see it, we can setup TFS to use WSS and then convert it to use MOSS 2010 next year. Or we can setup TFS to use MOSS 2007 and then convert it to use MOSS 2010 next year.

Any idea which is going to be more problematic? Can you expand on why? I couldn't find anything that seemed to relate specifically to TFS when migrating from MOSS 2007 to MOSS 2010. There's this information, but it's for converting from WSS to MOSS 2010: http://msdn.microsoft.com/en-us/library/ee462861.aspx

Any insight would be greatly appreciated.

vinay said...

Vignesh,

This is is a nice post. Great! What if if the list has more data say more than 500 MB of data and then migrate that to 2010 environment? As you know if the list has more than 500 MB of data it cannot be saved as a template.

Thanks,

Vinay.