Feature Stapling in SharePoint 2010 Part II
At this point Feature 1 is complete and we are ready to deploy to our sharepoint environment. You should have a solution explorer similar to this:
After you deploy, you can verify that everything worked by doing the following. Navigate to Site Actions -> Site Settings -> Site Collection Administration -> Site Collection Features. Search for the feature you deployed. You should find that it’s activated and working as expected.
The second thing we need to check is whether our master page was deployed or not. Navigate to http://[RootSite]/_catalogs/master/Forms/AllItems.aspx in your browser. You should find that Test.master (or whatever the name you gave) is now visible and approved in our master page list.
At this point we have feature 1 fully working. We won’t stop here because we want this master page to be applied whenever a new site collection is provisioned. So we have to create our Stapler (Feature2) which will associate Feature1 with the site definition of My sites.
Step 3: Create Stapler Feature to associate Feature1 with a site Definition
Follows the same steps above to create another Feature called Feature 2. The scope of this feature should be set to Farm level.
Next add an empty element item called Elements.
Your Solution explorer should like this now
The next task is the most important since this involves associating feature with a site definition.
We will need the GUID from Feature1 . You can find this in the manifest.
<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <FeatureSiteTemplateAssociation TemplateName="SPSMSITEHOST#0" Id="493a82e4-f05b-4244-91df-c99ba69db085"></FeatureSiteTemplateAssociation> <FeatureSiteTemplateAssociation TemplateName="SPSPERS#0" Id="493a82e4-f05b-4244-91df-c99ba69db085"></FeatureSiteTemplateAssociation> </Elements>
Two lines of code were added to make the association between feature and site defintion. The site definition id is encapsulated in the templatename [SPSMITEHOST#0 & SPSPERS#0].
We’ve now successfully created our feature and stapler. Deploy this to your SharePoint instance to see this in action.
Retrieving the current user in SharePoint 2010 object model How to generate an iCalendar file






Hi Samuel,
Thank you very much for taking the time to build this site with such detailed instructions.
I have followed all your steps and made sure I have added my customized master page.
The project deployed successfully without any error.
On the home page I do see the feature on the site collection as activated.
When I built a new site on one of the subsites, the customized site isn’t created.
What am I missing?
We use SQL 2008 with SharePoint 2010.
Thank you in advance.
Thank you for the article. It is the best I have found so far with regard to stapling. I have done exactly as it stated, yet when I deploy the feature is there, but not activated. I would like to have the feature activated each time I create MySite. Is it possible to have a solution sent to me or maybe some hints as to what could be done wrong. I am attaching the GUID from the Manifest from the main feature by clicking on the design view manifest link of the first feature and adding this GUID to the elements. This is kind of urgent and any help would be highly appreciated. Thank you.