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);

How to find all the customized master pages in a site collection

I got this question today from one of my collegues and needed to find the answer to it. Why did I get this question? Well one of our developper teqms provided a new solution to deploy that replaces the default master pages and the update did not show any difference after deployment. therefore we suspected that the master pages had somehow be customized which causes this behaviour.

My first hunch for finding the answer was SharePoint Designer and my favourite Microsoft Premier Support Engineer confirmed with the following article: Track Customized Master Pages

Basically you need to open the site collection using SharePoint Designer and run the Customized Pages report and apply a filter to show only the customized master pages

Below is the information that describes how to do this as grabbed from the Microsoft article

Run the Customized Pages report

For both Office SharePoint Server 2007 and Windows SharePoint Services 3.0, data for the reports generated by Microsoft Office SharePoint Designer 2007 is saved on the server on which the site is hosted. Server administrators can grant or deny access to these reports. If the reports generated come back empty, contact your server administrator for assistance. You must have at least Web Designer permissions on the server to open the site and run reports.

When you are working with an Office SharePoint Server 2007 or Windows SharePoint Services 3.0 site, you can easily use Office SharePoint Designer 2007 to run site reports that collect a variety of information about your site’s health, usage, and potential problems. To run a Customized Pages report:

  1. Open the Web site for which you want to run the report in Office SharePoint Designer 2007.
  2. On the Site menu, point to Reports, point to Shared Content, and then click Customized Pages.The report opens with all of the pages in the site listed, and the Customized column indicates whether content has been customized for that page. Note   A page is considered customized only if it is included in the original site definition. New pages created from a master page, new blank ASPX pages, and custom list forms that you create are not considered customized pages.


Filter the report to show only master pages

After you run the Customized Pages report, you may want to narrow it down to include only those pages in the site that are master pages, as shown in the following illustration.

  • To limit the results to master pages only, click the arrow next to the Type column heading, and then click master.

Filter the report to show only customized master pages

You can narrow the results even further to list only customized master pages, as shown in the following illustration.

  1. Click the arrow next to the Type column heading, and then click master.
  2. Click the arrow next to the Customized column heading, and then click Yes.

The report now lists only master pages that have been customized.

 Note   To remove any filter, click the arrow next to the column heading, and then click (All).

SWAT 2007

This is another one of those tools you should have on your SharePoint farm(s). Although the tool is aimed to designers of SharePoint solutions, I like to use it for deploying solutions to different or additional web applications without having to retract it first.

The official description, grabbed from the website states the following:

SharePoint Work Acceleration Toolkit (SWAT) is a windows based utility aimed at simplifying and accelerating the creation and testing of SharePoint Solutions. With a whole host of time saving capabilities and planned integration with Universal SharePoint Manager 2007, you’ll never want to take on SharePoint without it again.

SWAT Features and Capabilities:
Here is a short list of just some of the things SWAT can do. For a complete overview checkout the SWAT User Guide.

  • Site Diagramming
    • Show a Site Structure as a Diagram
    • Save a Site Structure Diagram as a Image
    • Save a Site Structure Diagram as a SVG file (for importing into Visio)
    • Print a Site Diagram
    • Drag and Drop the design of a Site Structure
  • Generate Test Data and Sites
    • Generate Random Sites for Testing
    • Auto Populate Lists/Libraries with Test Data (including Documents)
  • Work with SharePoint Logs
    • View SharePoint Log Files in a preview window
    • Group and Filter Log file entries
  • Work with Sites
    • Show a Site Structure in a Tree View (including security inheritence)
    • Create a Site Collection
    • Export and Import Site Structures
    • Backup and Restore Site Collections
    • View and Interact with site objects (Lists, Users, Roles, Features, Events, etc..)
    • Delete Sites and entire Site Structures
  • Work with SharePoint Features
    • View Feature Status in Farm and on a Site
    • Install and Uninstall Features
    • Activate and Deactivate Features
  • Work with SharePoint Solution Packages
    • Install and Deploy Solution Packages
    • View Solution Deployment Locations (Servers and Web Apps)
    • Deploy, Retract and Delete Solutions
  • Work with SharePoint Jobs
    • View Job Status
    • Add and Schedule Jobs
    • Enable and Disable Jobs
    • Force Execution of Jobs
  • Work with Event Receviers
    • Install Event Receivers for Sites and Lists
    • View and Manage Event Receivers
    • Delete Event Receivers
  • Work with Web Parts
    • Add (Deploy) Web Parts to multiple sites/pages
    • Replicate Web Parts
    • Delete Web Parts from multiple sites/pages

…and much much more!   These are just some of the features available in the SharePoint Work Acceleration Toolkit.

And now for the good part of this tool: ….. IT’S FREE

Read all about it here

SPS2003 Lock site using command line: SPSiteManager

yeah yeah, if you are used to working with MOSS, then you will probably tell me to use the command stsadm -o setsitelock -url <url> -lock readonly or something like that.

Unfortunately back in the SharePoint Portal Server 2003 and WSS 2.0 days, this operation was no yet available with stsadm…..along with a lot of other usefull commands

I needed to lock the sps 2003 sites in a gradual upgrade project to MOSS. Of course I want to script the complete migration, which also includes locking the SPS site before starting the upgrade.

Searching the web, I found my way to the SPSiteManager project on Codeplex 

In addition to the opeartions I was looking for, you also get the following operations:




Enumerate all Content Database information and generate a Site Distribution Document


Re-partition sites to different content databases


Enumerate Site Collections


Enumerate URL references from the list of sites to crawl


Enumerate URL references from a portals site directory


Enumerate Content Databases


Backup site(s)


Restore site(s)


Delete site(s)


Add content databases to a virtual server


Add site(s) to list of sites to crawl for SharePoint Portal Server 2003


Remove site(s) to list of sites to crawl for SharePoint Portal Server 2003


Add site(s) to Portal Server 2003 Site Directories


Remove site(s) to Portal Server 2003 Site Directories


Lock site(s)


Unlock site(s)


Reset quotas on site(s)


Purge document versions from document libraries

Although these operations look a lot like the ones we get with MOSS, nowadays, they actually are much better. For example the operation to backup a site will actually also lock the site for read/write for you and unlock it when done. So before using this tool with all the operations, be sure to check out the well written manual that is included explaining each operation.


Using SQL Aliases with SharePoint by Thomas Vochten

Thomas Vochten, a former colleague of mine, wrote about an interesting way to create and configure your SharePoint farm to take into account any possible changes in your backend SQL infrastructure by using SQL aliases on your MOSS servers and therefore adding the possibility to change your backend SQL server transparently to your SharePoint configuration.

On his blog, he wrote:

“I recently found out about SQL Aliases and how to use them in combination with SharePoint installations. It enables you to define local alias name to connect to with a SQL Client, so you can change the actual connection later on. This may come in handy when switching over to your mirror database server, when moving servers, when virtualizing you database server etc. “

Furthermore he describes the actual steps to configure this. I am not adding those steps to this blog post, to have you go look at the original post instead [8-|]

I also checked with my favorite Premier support Engineer form Microsoft to check if this is supported and he confirms it is. He aslo confirmed seeing this more and more for use with Excel Services and failover scenarios as suggested by Thomas.

**** Update ****
Also worth mentionning is Thomas’s comment on my question:

I wrote: “Just to be clear: this needs to be configured on the MOSS servers locally, right, and not on the SQL box? And if so, then it would need to be configured on all MOSS servers part of the farm, too, right? “

Thomas replied: “Indeed, it needs to be configured on every MOSS server. You could also do this after MOSS is already installed: configure the alias exactly as your existing connection, and change it when needed.”

Thanks Thomas for sharing.

SPS2003 Add Link to Site not working

Why might this be relevant to a MOSS admin. Well, you might be busy upgarding a SharePoint Portal Server 2003 environment to MOSS using the gradual approach, like I am. Off course you would test thjis on a test farm and reproduce your production environment in a somewhat representative way. In my case a imported only a couple of production sites in my test environment, which could be considered as logical.

Now, the thing is that I tried crawling the SPS content with my new MOSS farm and the crawl uses the Site Directory on the SPS Portal to anmalyze which sub sites it needs to crawl. Clearly the Site Directory was not reflecting teh istes I had on my test environment. So I cleaned out the Site Directory and wanted to add Links to the actual sites on the SPS application.Guess what, I was unable to. Apparently this is due to SP2 for SharePoint Portal Server 2003.

Thanks to this blog post I found the solution:

1. Open this file in a text editor:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\[LCID]\SPSSITES\LISTS\SITESLST\NewForm.aspx
(Replace [LCID] with your locale identifier, 1033 for English)

2. Find this code fragment:

<SPSWC:InputFormButtonSection runat=”server”>
<SPSWC:InputFormButtonAtBottom ID=”ButtonOk” runat=”server”
<SPSWC:InputFormButtonAtBottom ID=”ButtonCancel” runat=”server”
TextLocId=”Page_CancelButton_Text” visible=”false” />

3. Replace it with this code fragment:

<SPSWC:InputFormButtonSection runat=”server”>
<!– Workaround for WIN2003SP2 issue:
<input type=”button” value=”         OK         ”
onclick=”document.forms[0].submit()” />
<!– <SPSWC:InputFormButtonAtBottom ID=”ButtonOk” runat=”server”
TextLocId=”Page_OkButton_Text”/> –>
<!– End workaround –>
<SPSWC:InputFormButtonAtBottom ID=”ButtonCancel” runat=”server”
TextLocId=”Page_CancelButton_Text” visible=”false” />

4. Thats it;-)