Home > PowerShell, SharePoint 2010, SharePoint Administration > Fixing: This page is not using a valid page layout. To correct the problem edit page settings and select a valid page layout error in SharePoint 2010

Fixing: This page is not using a valid page layout. To correct the problem edit page settings and select a valid page layout error in SharePoint 2010

I recently ran into the error below when I tried to access a Wiki Page after I migrated over a SharePoint 2010 Enterprise Wiki Site from one location to another.

This page is not using a valid page layout. To correct the problem edit page settings and select a valid page layout.

This sometimes happens after a migration of SharePoint Publishing Site Pages because the page layout URL is “hardcoded” into the  aspx pages, and if you migrated from one location to another the possiblity of that page layout not exiting or is incorrectly listed in your page will throw this error.  SharePoint is not smart enough to update this.

If you were to download a copy of that page and open it up you would see that the URL for the PublishingPageLayout is “hardcoded” with the “old” or “non existing” page layout.  Look for the <tag>:

<mso:PublishingPageLayout msdt:dt=”string”>URL to Publishing Page Layout</mso:PublishingPageLayout>

You will see that the URL is more than likely pointing back to the location it was migrated from.

Now you can simply just edit this URL to point to the corrrect location, save it, and then re-upload it back into the library, but who wants to do that for every single Page?

Below is a PowerShell script I used to fix my issue with the Wiki Pages.  It will iterate through all the Pages in the Publishing Pages library, check to see if the Pagelayout URL is incorrect, fix it, and check the page back in.

——————————————————————————————————————

#GET WEB
$web = Get-SPWeb -Identity http://portal-new/site/wiki

$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$spPages = $pubWeb.PagesLists;

#STORE MASTERPAGE LOCATION FOR ENTERPRISE WIKI INTO $PAGELAYOUT VARIABLE
$pageLayout = “/_catalogs/masterpage/EnterpriseWiki.aspx”

#STORE MASTERPAGE FOR ENTERPRISE WIKI NAME INTO $PAGELAYOUTNAME VARIABLE
$pageLayoutName = “Basic Page”

#LOOP THROUGH THE ITEMS OF THE WIKI PUBLISHING PAGES TO GRAB PAGE LAYOUT URL
foreach ($item in $spPages.Items)
{

$pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
$pubUrl = New-Object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())

if ($pubUrl -ne $null)
{
$itemPubUrl = $pubUrl.Url

#IF PAGE LAYOUT URL IS INCORRECT, UPDATE PAGE LAYOUT URL, COMMIT CHANGES, AND CHECK PAGE IN.
if ($itemPubUrl -like http://portal-old/site/wiki*)
{
$newPubUrl = New-Object Microsoft.SharePoint.SPFieldValue(http://portal-new/site/wiki + $pageLayout, $pageLayoutName)

$pubPage.Name

Write-Host “Updating PageLayout for ” $pubPage.Name -foregroundcolor Yellow

$pubPage.CheckOut()
$pubPage.ListItem[[Microsoft.SharePoint.PublishingFieldId]::PageLayout] = $newPubUrl
$pubPage.ListItem.UpdateOverWriteVersion()
$pubPage.ListItem.File.CheckIn(“Fixed URL To Page Layout.”, [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);

}
}
}
——————————————————————————————————————–

After executing the script all the Page Layout URL’s should be updated to point to the correct Page Layout and you should no longer get that error.

Advertisements
  1. June 21, 2014 at 11:52 am

    Please let me know how to execute the above power shell script,I am unable to execute the above query

  2. June 22, 2014 at 2:55 pm

    Hi,Same issue I am facing,kindly let me know how to run above script,because i am getting error when running above script on share point power-shell editor.

    • June 23, 2014 at 8:29 am

      HI hasansan, what type of error are you receiving?

  3. Cat
    July 10, 2014 at 3:05 pm

    hello in line 2 there should be a dot between the publishing and publishing

  4. Jordan
    August 14, 2014 at 12:11 pm

    This looks like a great solution. But I keep getting an error: Missing ‘]’ after array index expression.
    At C:\fixpagelayout.ps1:34 char:73
    + $pubPage.ListItem[[Microsoft.SharePoint.PublishingFieldId]::PageLayout <<<<
    = $newPubUrl]
    + CategoryInfo : ParserError: (CloseSquareBracketToken:TokenId) [
    ], ParseException
    + FullyQualifiedErrorId : MissingEndSquareBracket

    Any ideas?

    • August 14, 2014 at 12:22 pm

      Hi Jordan,

      This is a typo by me. I forgot the closed ‘]’ after PageLayout

      Try this.

      $pubPage.ListItem[[Microsoft.SharePoint.PublishingFieldId]::PageLayout] = $newPubUrl

      Let me know if that helps.

      Thanks

      v/r
      JShidell

  5. Jordan
    August 14, 2014 at 12:42 pm

    Awesome, thanks! I should have picked up on that. It fixed that error but now I’m getting two other errors:

    Unable to find type [Microsoft.SharePoint.Publishing.PublishPage]: make sure th
    at the assembly containing this type is loaded.
    At C:\fixpagelayout.ps1:17 char:57
    + $pubPage = [Microsoft.SharePoint.Publishing.PublishPage] <<<< ::GetPublishing
    Page($item)
    + CategoryInfo : InvalidOperation: (Microsoft.Share…ing.Publish
    Page:String) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

    Cannot index into a null array.
    At C:\fixpagelayout.ps1:18 char:77
    + $pubUrl = New-Object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[
    <<<< [Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())
    + CategoryInfo : InvalidOperation: (0f800910-b30d-4c8f-b011-8189b
    2297094:Guid) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    • August 14, 2014 at 12:48 pm

      Hi Jordan,

      Do you mind posting your script so I can take a better look at it? I might be able to determine right away what is wrong.

      Thanks

      v/r
      JShidell

      • Jordan
        August 14, 2014 at 12:52 pm

        No problem, I’ll just replace my URL’s with new-URL and old-URL:

        #GET WEB
        $web = Get-SPWeb -Identity http://new-URL.com/sites/sbctest4

        $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
        $spPages = $pubWeb.PagesLists;

        #STORE MASTERPAGE LOCATION FOR ENTERPRISE WIKI INTO $PAGELAYOUT VARIABLE
        $pageLayout = “/_catalogs/masterpage/RCLayoutTwoColumnWideLeftWebpart.aspx”

        #STORE MASTERPAGE FOR ENTERPRISE WIKI NAME INTO $PAGELAYOUTNAME VARIABLE
        $pageLayoutName = “RCLayoutTwoColumnWideLeftWebpart”

        #LOOP THROUGH THE ITEMS OF THE WIKI PUBLISHING PAGES TO GRAB PAGE LAYOUT URL
        foreach ($item in $spPages.Items)
        {

        $pubPage = [Microsoft.SharePoint.Publishing.PublishPage]::GetPublishingPage($item)
        $pubUrl = New-Object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())

        if ($pubUrl -ne $null)
        {
        $itemPubUrl = $pubUrl.Url

        #IF PAGE LAYOUT URL IS INCORRECT, UPDATE PAGE LAYOUT URL, COMMIT CHANGES, AND CHECK PAGE IN.
        if ($itemPubUrl -like “http://old-URL.com/*”)
        {
        $newPubUrl = New-Object Microsoft.SharePoint.SPFieldValue(http://new-URL.com/sites/sbc + $pageLayout, $pageLayoutName)

        $pubPage.Name

        Write-Host “Updating PageLayout for ” $pubPage.Name -foregroundcolor Yellow

        $pubPage.CheckOut()
        $pubPage.ListItem[[Microsoft.SharePoint.PublishingFieldId]::PageLayout] = $newPubUrl
        $pubPage.ListItem.UpdateOverWriteVersion()
        $pubPage.ListItem.File.CheckIn(“Fixed URL To Page Layout.”, [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);

        }
        }
        }

  6. Jordan
    August 14, 2014 at 12:54 pm

    I just noticed that $newPubUrl = New-Object Microsoft.SharePoint.SPFieldValue(http://new-URL.com/sites/sbc + $pageLayout, $pageLayoutName) is wrong. But I updated that to $newPubUrl = New-Object Microsoft.SharePoint.SPFieldValue(http://new-URL.com/sites/sbctest4 + $pageLayout, $pageLayoutName) and am still getting the same errors

    • August 14, 2014 at 1:04 pm

      Hi Jordan,

      I think I found the problem.

      You have – $pubPage = [Microsoft.SharePoint.Publishing.PublishPage]::GetPublishingPage($item)

      Instead of PublishPage put PublishingPage.

      so – $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)

      Let me know if that helps.

      Thanks

      v/r
      JShidell

  7. Jordan
    August 14, 2014 at 1:12 pm

    Thank you!! That got rid of the first error, but I’m still getting:

    Cannot index into a null array.
    At C:\fixpagelayout.ps1:18 char:77
    + $pubUrl = New-Object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[
    <<<< [Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())
    + CategoryInfo : InvalidOperation: (0f800910-b30d-4c8f-b011-8189b
    2297094:Guid) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    • August 14, 2014 at 3:27 pm

      Hi Jordan,

      Can you try to put quotations around the URL value in the SPFieldUrlValue.

      i.e.

      $newUrl = New-Object Microsoft.SharePoint.SPFieldUrlValue(“http://new-URL.com/sites/sbc” + $pageLayout, $pageLayoutName)

  8. Jordan
    August 14, 2014 at 6:50 pm

    I tried that, with no luck. But I did eventually get it all to work. Here’s my final result:

    #GET WEB
    $web = Get-SPWeb -Identity “http://test”

    #GET PUBLISHING PAGES
    $pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    $spPages = $pubWeb.GetPublishingPages()

    #STORE LAYOUT NAME YOU WANT TO CHANGE (WITH WILDCARDS *)
    $chngLayout = “*RCLayoutTwoColumnWideLeftWebpart.aspx”

    #STORE LOCATION FOR NEW PAGE LAYOUT INTO $PAGELAYOUT VARIABLE
    $pageLayout = “/sites/sbctest4/_catalogs/masterpage/RCLayoutTwoColumnWideLeftWebpart.aspx”

    #STORE NEW LAYOUT NAME INTO $PAGELAYOUTNAME VARIABLE
    $pageLayoutName = “RCLayoutTwoColumnWideLeftWebpart”

    #LOOP THROUGH THE PUBLISHING PAGES TO GRAB PAGE LAYOUT URL
    foreach ($publishingPage in $spPages)
    {
    $pubUrl = New-Object Microsoft.SharePoint.SPFieldUrlValue($publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())
    if ($pubUrl -ne $null)
    {
    $itemPubUrl = $pubUrl.Url
    #IF PAGE LAYOUT URL MATCHES CRITERIA
    if ($pubUrl.Url -like $chngLayout)
    {
    #SET NEW VALUES
    $newPubUrl = New-Object Microsoft.SharePoint.SPFieldUrlValue($pageLayout)
    $newPubUrl.Description = $pageLayoutName

    #OUTPUT PAGENAME, APPLY NEW VALUES, OUTPUT RESULTS
    Write-Host “Updating PageLayout for ” $publishingPage.Name -foregroundcolor Yellow
    $publishingPage.CheckOut()
    $publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newPubUrl
    $publishingPage.ListItem.UpdateOverWriteVersion()
    $publishingPage.ListItem.File.CheckIn(“Fixed URL To Page Layout.”, [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
    Write-Host “URL: ” $newPubUrl.Url
    Write-Host “Descr.: ” $newPubUrl.Description
    }
    }
    }
    Write-Host -ForegroundColor red “FINISHED”

  9. Jordan
    August 14, 2014 at 6:53 pm

    Can you please edit that last comment to remove my URL’s? I forgot to before posting. Thanks!

    And thank you for your help with this!!

    • August 15, 2014 at 8:25 am

      Hi Jordan,

      Glad you were able to figure it out. Glad I was able to help.

  10. Pratik Vyas
    December 2, 2014 at 8:15 am

    Reblogged this on Pratik's SharePoint Blog.

  11. Lukasz
    May 8, 2016 at 4:09 pm

    There are many errors in your script and I couldn’t make it working.
    I found other simple script that solved my issue:

    $spWeb = Get-SPWeb(“http://currentsitename/webname”)
    $spFile = $spWeb.GetFile(“http://currentsitename/webname/Pages/Test-Page.aspx”)
    $spFile.CheckOut(“Online”,$null)
    $spFile.Properties[“PublishingPageLayout”] = “/_catalogs/masterpage/EnterpriseWiki.aspx, Basic Page”
    $spFile.Update()
    $spFile.CheckIn(“Update page layout via PowerShell”,[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
    $spWeb.Dispose()

    Hope this help!

    • June 14, 2016 at 1:49 pm

      Hi Lukasz,
      Your code helped me a lot

      Thank you so much

  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: