How to Ghost back or uncustomize customized Page Layouts

In followup of my previous post, today my favourite Microsoft Premier Support Engineer was asked to provide a way to unghost customized page layouts.
He came up with a little piece of code that does the trick in a C# Console application.

It must be getting clear to some of you that for administering SharePoint a knowledge of .Net development skills is becoming more and more a requirement….

The most important function of this piece of code depends on the method SPFile.RevertContentStream() which is described as: “Returns the file to its original uncustomized state so that its logic becomes cached in memory (also known as “ghosted”) rather than stored in the database.”

So, here it is. The folowing code will uncustomize the customized page layouts.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Publishing;

namespace GhostLayoutPages
  class Program
    static void Main(string[] args)
      using (SPSite site = new SPSite(args[0].ToString()))
        using(SPWeb web = site.OpenWeb())
          PublishingSite pubSite = new PublishingSite(site);
          PageLayoutCollection pageColl = pubSite.PageLayouts;
          foreach (PageLayout layout in pageColl)
            SPFile currFile = web.GetFile(layout.ServerRelativeUrl);
            Console.WriteLine(“Layout page name: “ + layout.Name);
            Console.WriteLine(“Status before: “ + currFile.CustomizedPageStatus);
            Console.WriteLine(“Status after: “ + currFile.CustomizedPageStatus);

5 thoughts on “How to Ghost back or uncustomize customized Page Layouts

  1. There is another option how to do this through Sharepoint UI
    SiteAction->Look and feel->Reset to site definition
    And right here u can chose whatever u want reset specific file or all pages of the site

Leave a Reply

Your email address will not be published. Required fields are marked *