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.

 

Print | posted @ Friday, February 22, 2008 8:16 PM

Comments on this entry:

Gravatar # re: Customizing the My Site look and feel
by Mirjam at 7/18/2008 1:43 PM

Hi Ajay,

For starters: it's always better to add a custom site definition then adjusting the default one.

But to answer your question...
A site definition is build up out of at least three files:

* An onet.xml file that is deployed in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\<name of the site definition>\xml folder. Changes to the onet.xml will not effect existing sites. This can be handy sometimes, but it can also be a pain in the ass if you want to make adjustments to all your existing sites.

* A default.aspx file that is deployed in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\<name of the site definition> folder. This file contains the web part zones and adjustments will also effect existing sites. This will however not effect data, only the visibility of web parts placed in web part zones that you change or delete can be effected.

* A webtemp.xml file in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\<LCID>\XML folder. This is merely the registration of your site definition and some metadata, like the visibility of the site definition to the end user. Changes to this file will also not effect existing sites and will not effect any data.

So the answer is "No, you will not lose data if you change a site definition" ;:-).

Regards,
Mirjam
  
Gravatar # re: Customizing the My Site look and feel
by Mirjam at 7/18/2008 1:59 PM

Hi Flo,

Your stylesheet can be deployed in two locations.
* The stylelibrary
* The file system in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\<LCID>\STYLES folder

We deploy our stylesheets to the styles folder on the file system. Deployment to this folder will be automatic. You could build a feature for this and in the feature receiver write some code that will copy the stylesheet from the feature folder to the styles folder.

If you want to deploy your stylesheet to the stylelibrary you can add your stylesheet to the design feature.
The contents of your design.xml elements file would then be extended with:
<Module Name=”Stylesheets” Url=”Style Library”>
<File Url=”Custom.css” Type=”GhostableInLibrary” />
</Module>
</Elements>

The <ElementManifests> tag of the feature.xml should also be extended with:
<ElementFile Location="StyleSheets\custom.css">

This means that the stylesheet with the name custom.css is stored in the StyleSheets folder in the feature folder.

I hope this helps...

Regards,
Mirjam

  
Gravatar # re: Customizing the My Site look and feel
by Leon Zandman at 7/23/2009 1:29 PM

Mirjam,

I just noticed you have embedded your feature receiver code inside using-statements. This causes the SPWeb instances to be disposed. I don't think you should be doing that (I think they are equal to instances obtained using SPContext). The code that calls your feature receiver methods will do the cleanup.

Greetz,

Leon
  
Gravatar # Links (2/24/2008) &amp;laquo; Steve Pietrek&amp;#8217;s SharePoint Stuff
by stevepietrekweblog.wordpress.com at 2/25/2008 1:05 AM

  
Gravatar # SharePoint Kaffeetasse 46
by feeds.feedburner.com at 2/26/2008 8:11 AM

  
Gravatar # Bookmarking the web - w10/2008
by www.d2design.be at 3/9/2008 4:09 PM

  
Gravatar # sharepoint mysite
by ryan.onlinepokervidsdirect.info at 7/11/2008 11:31 PM

  
Gravatar # [Best Practices] Customisation du My Site : Comment le modifier en amont et en aval
by blogs.codes-sources.com at 9/5/2008 8:48 AM

  
Gravatar # re: Customizing the My Site look and feel
by Paul at 11/30/2009 10:06 PM

Do you happen to have the project files for this sample available for download?
  

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 2 and 3 and type the answer here: