Page layout is empty after ghosting (uncustomising = reseting to definition)

Symptom:

You have a page layout deployed in a custom feature. At some time there were some SharePoint Designer modifications to it, then there was SP 2007 > 2010 migration through database attach. You want to reverse page layout to definition. You have done it and all all the sudden you have nothing on the page: no content, no webparts, nothing!

You look at page layout content and it only has this code:

<%@ Page language=”C#”   Inherits=”Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,
Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”SharePointWebControls” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Register Tagprefix=”WebPartPages” Namespace=”Microsoft.SharePoint.WebPartPages” Assembly=”Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Register Tagprefix=”PublishingWebControls” Namespace=”Microsoft.SharePoint.Publishing.WebControls” Assembly=”Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Register Tagprefix=”PublishingNavigation” Namespace=”Microsoft.SharePoint.Publishing.Navigation” Assembly=”Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<asp:Content ContentPlaceholderID=”PlaceHolderPageTitle” runat=”server”>
<SharePointWebControls:FieldValue id=”PageTitle” FieldName=”Title” runat=”server”/>
</asp:Content>
<asp:Content ContentPlaceholderID=”PlaceHolderMain” runat=”server”>
</asp:Content>

Not your code! No zones, no webparts, no content controls.

I looked in SharePoint Manager 2010 and what I noticed is that vti_setuppath points to standard SharePoint resource and not my custom feature FeaturesMyFeatureCustomLayout.aspx  I don’t have a clue why it happened for this particular page layout. It may have something to do to the fact that layout was customised and/or it was once deployed with dreadful meta tag produced by SharePoint designer “meta:progid=”SharePoint.WebPartPage.Document”

Image

Anyway,

to fix the issue, what I did was:

1. Add additional File to my feature elements:

<File  Url=”CustomLayout2.aspx”  Path=”CustomLayout.aspx” Type=”GhostableInLibrary” IgnoreIfAlreadyExists=”TRUE” >
<Property Name=”Title” Value=”Bla bla title” />
<Property Name=”ContentType” Value=”$Resources:cmscore,contenttype_pagelayout_name;” />
</File>

Note: you dont need to add phisical file to this module, you are just tell SharePoint to instantiate a file in masterpage gallery pointing to your CustomLayout.aspx

2. ReDeploy a new solution, and reactivate feature

3.Run this script, here I used help from this post: http://www.insidesharepoint.net/post/2011/06/21/How-to-fix-renamed-page-layout-features.aspx

But with some modifications. All it does is to Move good content of file 2 to corrupted file 1. So at the end of the day, CustomLayout2.aspx will not be there, only CustomLayout.aspx but with right properties and content.

function overwritePageLayout($oldFilePath, $newFilePath)
{
$spsite = Get-SPSite -Identity $projectUrl;
$web = $spsite.OpenWeb(“/”);

if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web) -eq $true)
{
$pubsite = new-object Microsoft.SharePoint.Publishing.PublishingSite($spsite);
$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);
$pageLayouts = $pubsite.GetPageLayouts($true);

$oldFile = $null;
$newFile = $null;

$nrOld = 0;
$nrNew = 0;

$pageLayouts | ForEach-Object {
$file = $_.ListItem.File;
if($file.Name -eq $brokenlayout)
{
$oldFile = $file;
$nrOld += 1;
}
if($file.Name-eq $replacinglayout)
{
$newFile = $file;
$nrNew += 1;
}
}
if($newFile -ne $null -and $oldFile -ne $null)
{
Write-Host “–> Moving file” $oldFile.Properties["vti_setuppath"]
$newFile.MoveTo($oldFile.Url, $true);
}
elseif( $oldFile -ne $null -and $newFile -eq $null)
{
Write-Host “Could not find correct file ($nrOld invalid files found)”;
}
if ($nrNew -gt 1)
{
Write-Host “Multiple files ($nrNew) with same setuppath found”;
}
}
$web.Close();
$spsite.Close();
}

Write-Host “This script will fix broken page layout”

$projectUrl = “http://siteURL

$brokenlayout = “CustomLayout.aspx”
$replacinglayout = “CustomLayout2.aspx”

$spsite = Get-SPSite -Identity $projectUrl;
$web = $spsite.OpenWeb(“/”);

if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web) -eq $true)
{
$pubsite = new-object Microsoft.SharePoint.Publishing.PublishingSite($spsite);
$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);
$pageLayouts = $pubsite.GetPageLayouts($true);
$pageLayouts | ForEach-Object {
$file = $_.ListItem.File;
$file.Name
}
}

overwritePageLayout($brokenlayout , $replacinglayout)

Leave a Reply