Customizing the My Site look and feel

As a reaction to my post about adjusting the top level navigation on My Sites I got an email asking how you go about adjusting the look and feel of a My Site. Since I also touch upon that topic in a lot of my presentations I decided to write it down.

The problem with putting a design on My Sites is that you can't change the master page and the style sheet of your My Site through the user interface. This problem also occurs when you migrate a SharePoint 2003 environment with (a lot of) My Sites to SharePoint 2007. All these My Sites need to get the correct visual design and since all My Sites are site collections they can't inherit their master page and style sheets either.

I wanted to create a solution to this problem for both existing sites and new sites. I will use this blog post to describe the solution.


The basics

For both the deployment of a design on existing My Sites and the activation of a design on new My Sites a feature with the master page is needed. Also a style sheet needs to be deployed. The design feature looks like this:

The feature.xml file stores the metadata of the feature.

The scope of the feature is "Web"(=sub site) where you might expect "Site"(= site collection), the reason I chose web was that if you have a site with a lot of sub sites and you want to save one of the sub sites as a template and the sub site inherits it's master page from the site collection it resides under it occasionally won't save the correct design in the template.

There are two files that need to be deployed with this feature, the master page file and the element manifest file of the feature, design.xml. There is also a feature receiver for this feature that, on activation and deactivation will set the correct master page, style sheet and title graphic.

The element manifest file design.xml describes the inner workings of the feature. In this case the main purpose of the feature is to deploy the custom master page to the master page gallery.

The style sheet is deployed from a separate project that is used to deploy custom files to the MOSS 2007 12 directory (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\). The structure of this project is the same as the structure of the 12 directory.

The featurereceiver will take care of assigning the correct master page and style sheet to each sub site the feature is activated on. If the feature is deactivated the default master page will be assigned again and no custom style sheet will be applied.

 


New sites

In order to activate the feature on all My Sites that are created from the moment you activate your feature on you can build a stapling feature. Feature stapling is a very cool thing in MOSS 2007 where you can build a separate feature to tie site definitions and features together.  Using feature stapling you can create an blank site (not based on the MOSS 2007 blank site!) and staple all functionality you want to that site definition. The features that are stapled to a site definition are activated when the site is created. Feature stapling can create n-to-n relations. One feature can be stapled to several site definitions and several features can be stapled to one site definition.

The stapling feature also has a feature.xml for it's metadata. The most prominent setting in the feature.xml is the fact that the feature is activated at the "Farm" scope. This means that it will work on all web applications within the farm. This is fine, since in most environments only one web application is used for My Sites and the feature is only stapled to the My Sites site definition as you can see in the element manifest file of the stapling feature, DesignStapling.xml. This ensures that on every site that is created with the My Site site definition the design feature is activated.

 

If you didn't want to create this functionality just for My Sites, but you would build it for all sites you could staple to the GLOBAL site definition. All other site definitions inherit from the GLOBAL site definition, so stapling the design feature to this will staple the design feature to almost all site types. A prominent exception on this is the blank site. In the site definition of the blank site it is defined that you can not staple anything to the blank site (AllowGlobalFeatureAssociations="False"). This is necessary, because SharePoint itself also staples features to the GLOBAL site definition and otherwise the blank site would not be blank.


Existing sites

Feature stapling will only have an effect on sites that are created after you stapled the feature to the site definition. This means that if you already have a lot of My Sites that you want the custom design activated on you need to think of something else.
For this purpose I created a simple console application that loops through all sub sites within a web application and that activates the feature on all of them. This feature can also be used to deploy changes in the master page to already existing sites.

The application application can both activate and deactivate the design on a specific web application. In order to start it you use on of the following options:

  • -o activatedesign -url [webapp url]
  • -o deactivatedesign -url [webapp url]

Depending on whether you entered the activating or deactivating operation the application will go to the activating or deactivating function. The code for both of them is displayed below.