Home > SharePoint > Fixing pages and their layouts after importing a published site

Fixing pages and their layouts after importing a published site

If you export a publishing site from one farm and import it to another, you may be surprised that none of your pages will work.  I recently got the following error:

 

image

The problem is the page is hard-coded to the page layout from the original site.

The following Powershell script that my buddy Raj wrote will fix the problem:

 

Code Snippet
  1. function LoadSharePointPowerShellEnvironment
  2. {
  3.     write-host
  4.     write-host "Setting up PowerShell environment for SharePoint" -foregroundcolor Yellow
  5.     write-host
  6.     Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
  7.     write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
  8. }
  9.  
  10. write-host
  11. LoadSharePointPowerShellEnvironment
  12.  
  13. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
  14. [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")
  15.  
  16. $web = Get-SPWeb -Identity "http://myserver/sites/sales/wiki"
  17.  
  18. $spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
  19. $pages = $spPubWeb.PagesList
  20.  
  21. foreach($item in $pages.Items)
  22. {
  23.   $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
  24.  
  25.   $url = new-object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())
  26.   if($url -ne $null)
  27.   {   
  28.   $ss =$url.Url
  29.     if($ss -match'TreeWikiLayout')
  30.   {  
  31.   $newurl = new-object Microsoft.SharePoint.SPFieldUrlValue("http://myserver/sites/sales/_catalogs/masterpage/TreeWikiLayout.aspx, Enterprise Wiki Layout with Tree")
  32.   $pubPage.Name
  33.   $pubPage.CheckOut()
  34.   $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl
  35.   $pubPage.ListItem.UpdateOverwriteVersion()
  36.  
  37.   $pubPage.ListItem.File.CheckIn("Fixed URL to page layout.", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
  38.   }
  39.     elseif($ss -match'EnterpriseWiki')
  40.   {
  41.   $newurl = new-object Microsoft.SharePoint.SPFieldUrlValue("http://myserver/sites/sales/_catalogs/masterpage/EnterpriseWiki.aspx, Basic Page")
  42.   $pubPage.Name
  43.   $pubPage.CheckOut()
  44.   $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl
  45.   $pubPage.ListItem.UpdateOverwriteVersion()
  46.  
  47.   $pubPage.ListItem.File.CheckIn("Fixed URL to page layout.", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
  48.   
  49.   }
  50.   }
  51.  
  52. }

 

It’s a little odd that this issue was carried over from 2007 to 2010, but there you go….

Advertisements
Categories: SharePoint Tags:
  1. Sean Jamison
    June 23, 2011 at 2:22 pm

    Donal saves the day again! Thanks, Donal.

  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: