Quantcast
Channel: Real SharePoint
Viewing all articles
Browse latest Browse all 11

Ghosting of Page Layout or Publishing Page

$
0
0
Sometimes we have a scenario where we need to ghost or uncustomize the page, 
Following is the code for the same,

SPSecurity.RunWithElevatedPrivileges(delegate()
{
  using (SPSite site = new SPSite(sSiteURL))
  {
    PublishingSite publishingSite = new PublishingSite(site);
    PageLayoutCollection pageCollection = publishingSite.PageLayouts;
    foreach (PageLayout layout in pageCollection)
    {
      SPFile currentFile = site.RootWeb.GetFile(layout.ServerRelativeUrl);
      if (currentFile.CustomizedPageStatus == SPCustomizedPageStatus.Customized || currentFile.CustomizedPageStatus == SPCustomizedPageStatus.None)
      {
        try
        {
          currentFile.RevertContentStream();
          currentFile.Versions.DeleteAll();
          currentFile.Update();
          site.RootWeb.Update();
        }
        catch (Exception ex)
        {
        }
      }
    }
  }
 });


Viewing all articles
Browse latest Browse all 11

Trending Articles