My First Post – SharePoint Customization to a new level

So finally I have got hooked to the blogs phenomena and have decided to join the "Blog Bandwagon". Although I am a rookie with SharePoint, but I guess I can also contribute my share to the vast ocean of SharePoint Knowledgebase.

So as the first post for my blog I would be discussing on some cool requirement where my customer required help in implementing – “How to restrict the available page layouts in a custom site definition”.

So the possible approaches to implement this would be:-

Strategy 1: Make changes in the Custom Site definition’s Onet.Xml file:

Steps to achieve this solution:

1.       Open the onet.xml of the custom site definition. This can be found typically at (DriveName\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Templates\CUSTOM SITE DEF\Onet.XML).

2.       Find the webfeatures tag.

3.       Find the property AvailablePageLayouts and add the highlighted code below to the value part of the property.

<Property Key="AvailablePageLayouts" Value="~SiteCollection/_catalogs/masterpage/RedirectPageLayout.aspx:~SiteCollection/_catalogs/masterpage/WelcomeSplash.aspx"/>

4.       Do an iisreset or reset the application pool of the site

(+) of this approach - as I see it:

a.       All changes are made in the configuration file, hence no code involved.

b.      Good for new sites to be created.

(-) of this approach - as I see it:

.       a. Provides little or no support for existing sites

Strategy 2: And of course, you can make changes to the page layout collection through code :

As I always say “Never underestimate the power of a Developer, more so a SharePoint Developer”. You require a small piece of code to achieve the requirement.

I have written the sample code piece using Object Model and this could very easily be implemented in the FeatureActivated event handler.


SPSite thisSite = new SPSite("http://MOSS Site URL");

SPWeb thisWeb = thisSite.OpenWeb();

      PublishingSite thisPubSite = new PublishingSite(thisSite);

      PublishingWeb thisPubWeb = PublishingWeb.GetPublishingWeb(thisWeb);

      PageLayoutCollection myLayouts = thisPubSite.GetPageLayouts(true);

// Create a temp array

      // Copy required page layouts to the temp array

      // You can write your custom code to pick the required layouts

      // Possibly a for loop can also be used

      PageLayout[] msTemo = new PageLayout[3];

      msTemo[0] = myLayouts[0];

      msTemo[1] = myLayouts[1];

      msTemo[2] = myLayouts[2];

      // Attach the temp array to the SetAvailablePageLayouts Method

      thisPubWeb.SetAvailablePageLayouts(msTemo, false);



(+) of this approach - as I see it:

a.       Works well for existing sites. Once a site is created simply execute the code or if the code is implemented using a Feature Activated, add this feature to the site definition and it would work seamlessly well.

b.      As a developer, I like this strategy as it gives me power to control the features and as well ease in maintenance.

(-) of this approach - as I see it:

a.       I know none.