Del via


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.

<Code>

SPSite thisSite = new SPSite("https://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);

      thisPubWeb.Update();

</Code>

(+) 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.

Comments

  • Anonymous
    June 15, 2008
    PingBack from http://stevepietrek.com/2008/06/15/links-6152008/

  • Anonymous
    November 05, 2008
    原文链接:http://blogs.msdn.com/varun_malhotra/archive/2008/06/14/my-first-blog-post.aspx

  • Anonymous
    September 18, 2010
    Rajasthan is a popular tourist destination in India. It is the largest state in India to have many attractions to offer its visitors. There are many fascinating tourist attractions in the state dotted with several attractions catchy. The state is globally famous for its unique cultural and geographical characteristics. Desert, mountains, sand dunes, forests, flora & fauna, etc are the geographical characteristics of the state.

  • Anonymous
    October 10, 2010
    I enjoyed to be at here because one of my point has been cleared here. Blogs are becoming the main source of knowing about things certainty,its importance,idolizing,either in a marketing way that one can differentiate.

  • Anonymous
    October 10, 2010
    Nice post! I loved it your way of information..Good blog, great PIcs. I need more tips & info for this..

  • Anonymous
    October 10, 2010
    Keep up the good work.Your article is really great and I truly enjoyed reading it.Waiting for some more great articles like this from you in the coming days.

  • Anonymous
    June 24, 2011
    I am really moved by the points mentioned in the blog, which I have read no where else. It has been a real pleasure to visit this site. www.johareezwholesale.com