Thursday, September 19, 2013

Move a SharePoint Team Wiki Library between SharePoint Sites or Site Collections

In this post I describe how you can move a team wiki from one site to another. The difficulties here are:

  • The "Save as Template" option in the list settings does not exist. This is because this type of list is deprecated. In SharePoint 2010 you should use Enterprise Wikis.
  • After copying the list, the links in the wikis site must be adapted to the new site.

Ways to copy the Wiki Library

The are three "easy" ways to copy the Wiki Library from one site to the other. The "Save As Template" Link does not exist in the Library Settings but the option still exists.

SharePoint Designer

Open the site with the SharePoint Designer. Click on your wiki and go the the library settings. You'll find a "Save as template" button there.

"Save as Template" option in SharePoint Designer


SharePoint UI

You can use the standard "Save As Template" UI by modifying the URL

Go to the Wiki Library. Normally you browse the first wiki site, but go to the wiki library page by typing  /wikilibname/Forms/AllPages.aspx or by the Ribbon

"All Pages" in a wiki site
Now go the library settings.
Wiki Library Settings

Here change the url. Replace "listedit.aspx" by "savetmpl.aspx" in the browser and you will land at the "Save As Template" Site.
"Save as Template" form

PowerShell

You can also save a wiki template with PowerShell. This option is interesting for farm admins. Open the SharePoint Management Shell and type the following:


After the command ends succesfully you should have a template in your list templates gallery.


Download & Copy Template

Now download the template from the list templates gallery in the old site and upload it to your new site into the list templates gallery.


"List templates" gallery in your site collection

Upload a new template into your gallery


Create a new library from your template. Go to "View All Site Content" then "Create" and select your new template.

Adapt Wiki Links

To adapt the links within your wiki content either you do it manually or by PowerShell. If you haave the option to use PowerShell I can offer the following script.

Adapt the variables for your environment and start the script within the SharePoint Management Console. This script will loop through all your wiki items and adapt the links within your content.

 <# PowerShell Script to adapt Team Wiki Content Links after migration #>  
 # Setup Basic sites and pages  
 $teamWikiWebUrl = "http://sharepoint/sites/newweb"  
 $wikiListName  = "Applications Wiki"  
 $oldLink     = "/sites/oldweb/team%20wiki/"  
 $newLink    = "/sites/newweb/team%20wiki/"  
 try   
 {  
   Write-Host -foregroundcolor green " >> STARTING ..."  
   Write-Host -foregroundcolor green "`t1. Getting Wiki List."  
   $wikiWeb  = Get-SPWeb $teamWikiWebUrl  
   $wiki     = $wikiWeb.Lists[$wikiListName]  
   Write-Host -foregroundcolor green "`t2. Start adapting links."  
   foreach ($wikiItem in $wiki.Items) {                  
     # Replace the links in the new content  
     Write-Host -foregroundcolor green "`t`t>>Adapting links in: " $wikiItem.Name  
     $content   = $wikiItem["ows_WikiField"]  
     $newContent = $content -replace $oldLink, $newLink    
     # Add new content to the page  
     $wikiItem["ows_WikiField"] = $newContent  
     $wikiItem.Update()      
   }  
   Write-Host -foregroundcolor green  "`t3. All Links adapted !!"    
   $wikiWeb.Dispose()  
 }  
 catch [System.Exception] {  
   Write-Host "Error while adapting Wiki links...`n" -foregroundcolor red  
   $_.Exception.ToString();    
   exit  
 }   

No comments: