AAron nAAs

All MindsharpBlogs

AAron's SharePoint notepad

My Links

Archives

Blog Stats

My Sites

Updating Customized PageLayouts

After our SharePoint 2003 to MOSS 2007 migration, we ended up with many customized (unghosted) page layouts. Files like Unstructured.aspx, Standard.aspx, FAQ.aspx, ... existed in our database, but were not represented by any filesystem file (ghosted). And of course, I needed to modify all those files in each site collection.

What I would have preferred is to modify the underlying filesystem file to affect all the uncustomized files (ghosted), but that wasn't possible. I tried creating a solution that installed new page layouts with the same names and locations. That didn't make a difference since the file content was already in the database.

I experienced the following (when dealing with the migrated templates):

PublishingSite pubSite = new PublishingSite(rootWeb.Site);

PageLayoutCollection pageLayouts = pubSite.GetPageLayouts(false);

foreach (PageLayout pageLayout in pageLayouts)

{

    SPFile file = rootWeb.GetFile(pageLayout.ServerRelativeUrl);

    // All migrated files end up: SPCustomizedPageStatus.None

    if (file.CustomizedPageStatus != SPCustomizedPageStatus.Uncustomized)

    {

        // Throws: Cannot revert to the site definition version of this file. It is a custom file and is not part of the site definition.

        file.RevertContentStream();

    }

}

With file.CustomizedPageStatus always SPCustomizedStatus.None, it appears the files were never “intended“ to be ghosted/uncustomized.

With the exception on file.RevertContentStream(), it appears that the files MUST be part of a site definition.

This is missing from the properties: file.Properties["vti_hasdefaultcontent"]

This is missing from the properties: file.Properties["vti_setuppath"]

Gary had already found problems with trying to set the “vti_“ values to reghost a page, so I abandoned that path.

Is it possible to uncustomize (ghost) files with a feature, by putting a version on the file system, then reverting the current “cusomizations” to now be ghosted?

What I ended up doing is to cycle through all the page layouts, and if the Feature contains a file of the same name, then it read the file and updated the content with a new version. This works, but there really is no reason to have more than one version.

private void UpdatePageLayout(SPWeb rootWeb, string url, byte[] content)

{

    SPFile file = rootWeb.GetFile(url);

    file.CheckOut();

    file.SaveBinary(content);

    file.Update();

    file.CheckIn(WORKFLOW_COMMENT);

    file.Approve(WORKFLOW_COMMENT);

}

posted on Thursday, February 14, 2008 11:17 AM

Feedback

# re: Updating Customized PageLayouts 2/14/2008 4:20 PM Peter

I've had roughly similar problems with reghosting list view pages, and come to the same conclusion as you: to fix it, you have to dig in via the Object Model and manually revert the pages. In the case of list pages (e.g. NewForm.aspx), this gets a little tougher as you have to keep the data stored in the WebPartZone. But, at least it's possible.

Title  
Name  
Url
CAPTCHA
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments