Click here to Skip to main content
14,325,352 members

Creating branded my site in sharepoint

Rate this:
4.00 (5 votes)
Please Sign up or sign in to vote.
4.00 (5 votes)
8 Sep 2009CPOL
The article describes how one can apply cusom branding over my site in SharePoint such that whenever a user creates my site, custom branding is already applied to the site.


After a long time, I am back to CodeProject. This time, it is with SharePoint. One of the great strengths of SharePoint is collaboration and a core functionality of this feature is my site. My site is a user's personal site where one can do anything from updating one's profile to searching persons, adding them as colleagues, tracking changes in colleagues profile, writing blogs and a lot of other things. But all this is provided in SharePoint default look and feel and one has to be really SharePoint literate to apply his/her own look and feel. What if someone wants to have all users’ my site with a custom branding............. Go ahead....


Described below is how to ensure that my site created by SharePoint users will have custom master pages applied on site also to ensure that my site will contain some predefined pages with specified web parts. You will be happy to know that all this can be achieved with just three features and a few lines of code.

Implementing Branded My Site

Before going into the actual implementation, just refresh what feature stapling is.

Feature Stapling is a process in which a feature can be attached with site templates so that a site can be created with certain pre-activated features.

So what I did was to create a stapler feature which associated the following features with the my site definition:

  1. Publishing feature with all its pre requisite features (so that I can deploy my custom pages)
  2. A feature to apply custom master page with my site
  3. A feature to deploy pages with web parts
feature.xml for stapler feature
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="F9AB6989-A3A8-4df2-8254-76987DD4FAA5" Title="SiteStaplerFeature"

         Scope="Farm" Version="" 



         xmlns="">  <ElementManifests>
    <ElementManifest Location="Elements.xml" />
element.xml for stapler feature
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="F52F9522-4086-4341-8B88-4368139C1E37" 

	xmlns="" >







FeatureSiteTemplateAssociation is a tag to associate features with a site definition. Here TemplateName="SPSPERS#0" is used as this is the default my site template. Now the feature ids that are referred in element.xml file are as follows:

  • The first one (with id f6924d36-2fa8-4f0b-b16d-06b7250180fa) is the id of publishing infrastructure feature as it is needed to enable publishing feature on site to deploy custom pages.
  • The second (with id 6ED16B2A-209F-4531-BBCE-F7B3F0CB75A8) is a custom feature to deploy master page with site and set the default master page.
  • And the third (with id 06927A49-4124-4a91-BA61-DB0BD5155BF2) is a custom feature to deploy custom pages.

My Site Master Page feature: This feature contains a custom master page to deploy on my site and the activation code is associated with a feature which will apply the master page as default master page of site.

feature.xml for mysite masterpage feature
<?xml version="1.0" encoding="utf-8"?>
<Feature Id="6ED16B2A-209F-4531-BBCE-F7B3F0CB75A8" Title="MySiteMasterPage" 




         DefaultResourceFile="core" xmlns="" 

         ReceiverAssembly="MyAssembly.MyNameSpace, Version=, 
	Culture=neutral, PublicKeyToken=282025704650b387" 

    <ElementManifest Location="MySiteMasterPage\Module.xml" />
    <ElementFile Location="MySiteMasterPage\MySite.master" />
Module.xml for masterpage feature
<?xml version="1.0" encoding="utf-8"?>
<Elements Id="D8669972-4B6C-49b2-9A34-430DD5C296F6" 

	<Module Name="MySiteMasterPage" List="116" Url="_catalogs/masterpage">
    <File Path="MySiteMasterPage\MySite.master" Url="MySite.master" 

	Type="GhostableInLibrary" />    
Master Page Feature activation Code
public override void Featureactivating(SPFeatureReceiverProperties properties)
    SPSite site = (SPSite)properties.Feature.parent;
    SPWeb web = site.OpenWeb("");
    web.CustomMasterUrl = "/_catalogs/masterpage/MySite.master";web.Update();

Now the third feature which is used to deploy pages with custom web parts on my site is:

Feature.xml for mysitepages feature
<Feature xmlns= 





    Description="Deploys a custom page with some web parts.">
    <ElementManifest Location="MySitePages/elements.xml" />
    <ActivationDependency FeatureId="22A9EF51-737B-4ff2-9346-694633FE4416" />
    <ActivationDependency FeatureId="A392DA98-270B-4e85-9769-04C0FDE267AA" />
    <ActivationDependency FeatureId="AEBC918D-B20F-4a11-A1DB-9ED84D79C87E" />
    <ActivationDependency FeatureId="89E0306D-453B-4ec5-8D68-42067CDBF98E" />
    <ActivationDependency FeatureId="D3F51BE2-38A8-4e44-BA84-940D35BE1566" />

The features in the tag <ActivationDependencies> are hidden features of SharePoint which require to be activated to activate publishing feature. So you can use this tag as it is in your feature.

Element.xml for mysite pages feature
<Elements xmlns="">  
	<Module Name="Pages" List="850" Url="Pages">
    <File Name="SearchResult.aspx" Url="SearchResult.aspx" 

	Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" >
      <AllUsersWebPart WebPartZoneID="Header" WebPartOrder="1">
  <webPart xmlns="">    <metaData>
      <type name="Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart, 
	Microsoft.Office.Server.Search, Version=, Culture=neutral, 
	PublicKeyToken=71e9bce111e9429c" />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
        <property name="CacheXslStorage" type="bool">True</property>
        <property name="Default" type="string" />
        <property name="ChromeState" type="chromestate">Normal</property>
           ..............other properties..................

A page with name SearchResult.aspx should be present in this feature folder with a webpart zone id "header". I have used webpart XML for people core search result webpart here. If you want to use custom webpart on a page, just export the webpart and paste webpart XML inside AllUsersWebPart tag.

Points of Interest

The thing that I really liked while implementing this requirement was that I didn't have to write thousands of lines of code. It was all about activating features and just 10 lines of code to apply the master page on site.


Here I have described all we need to create a branded my site for all users. We discussed feature stapling, publishing feature, applying master page on the site and deploying pages with web parts. I tried to keep things as simple as possible. If anyone has any questions, I will be more than happy to reply. I will also try to upload features and code files as soon as possible.


  • 8th September, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

dixit gaurav
Web Developer Nagarro Software Pvt Ltd Gurgaon India.
India India
No Biography provided

Comments and Discussions

GeneralApply Master Pages to MySite in SharePoint 2010 Pin
Ashok.Yekula21-Dec-10 1:48
memberAshok.Yekula21-Dec-10 1:48 
Questionhow to create a webpart in sharepoint 2010 that allow user to create their own website... Pin
hinzhonee23-Aug-10 19:50
memberhinzhonee23-Aug-10 19:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 8 Sep 2009


11 bookmarked