SharePoint 2010 Feature Stapling
Written By: Shishir Bhandari -- 12/21/2010 --
(105) comments --
Categories: MOSS 2007, System Administration, WSS3
< Prev -
- Next >
| Become a paid author
When you start using SharePoint, you tend to explore what it offers out
of box. So you start using out of the box site definitions. But as time
passes you realize you need customizations in order to fulfill your
You can do this customization on each of the sites created from this
site definition OR you can customize the out of the box site definition
itself. The latter has a drawback though.
A SharePoint service pack upgrade would break any customization to out
of box site definition. Then What is the best way to add Customizations
on out of box sites? How would you apply your customizations on multiple
The solution is Feature Stapling!
This article deals with the Feature Stapling concept in SharePoint. I am assuming the reader knows how to create a feature. For more details refer to this msdn article.
In this article, we will cover
what Feature Stapling is, when to use Feature Stapling, and how to code Feature Stapling?
In "SharePoint Feature Stapling - Part 2", we will cover Common Issues with their solutions while coding Feature Stapling and few exceptional scenarios.
What is Feature Stapling?
Feature Stapling has two features. A "Stapler" feature which
staples another feature to the site definition and the "Staplee"
feature which will be stapled. Let's take an example to understand it.
Scenario: You want to apply a custom Theme to all of the "Publishing
site" site definitions.
This can be solved by creating a feature which will apply the Custom
theme to the site and it can be associated with the publishing site's
How to associate feature with sites / site definition?
A Feature can be associated with the sites / site definition in three
1. This is self explanatory: since we have many sites under
consideration, we can't go for this option.
- If the number of sites under consideration are
minimal and you don't mind activating your feature on
all the sites manually, then you can create a site
from that site definition and deploy your "custom theme"
feature to the site and activate it.
- If you already know all the required
customizations before creating the site, you can
include the features in the site definition (onet.xml)
before you use it to create sites.
- If you want to automatically provision your
feature when the user creates the site & you don't
want to include it in the <SiteFeatures> or <WebFeatures>
child elements of the <Configuration> element that
represents the site definition configuration, you can
use Feature Stapling. Another reason would be when you
want to do customizations on out of the box site
definitions, I recommend the use of Feature
2. Include the customization in site definitions. You can
include the feature in the onet.xml file of site definition in <webfeatures>
or <sitefeatures>. The section of the site definition which contains the
web or site level features associated with it is shown below:
<Configuration ID="1" Name="Blank">
<Module Name="DefaultBlank" />
<!-- BasicWebParts Feature -->
<Feature ID="00BFEA71-1C5E-4A24-B310-BA51C3EB7A57" />
<!-- Three-state Workflow Feature -->
<Feature ID="FDE5D850-671E-4143-950A-87B473922DC7" />
<Feature ID="00BFEA71-4EA5-48D4-A4AD-7EA5C011ABE5" />
<!-- TeamCollab Feature -->
<Feature ID="F41CC668-37E5-4743-B4A8-74D1DB3FD8A4" />
<!-- MobilityRedirect -->
Here the ID in the feature tag is the Feature ID/ GUID. The
Sitefeatures tag has features which will be activated when this
site definition is used to create a site collection, whereas,
the Webfeatures tag has features which will be activated
when this site definition is used to create a web.
Since we have to customize the (out of the box) "Publishing
Site" site definition, we can't go for this option.
If you want to know more about creating custom site definitions,
this msdn article.
3. Feature Stapling
Feature Stapling is achieved through the creation of another
feature ("stapler") that defines the association of your
regular Feature (the feature carrying your "Custom Theme")
and the site definition you want to "staple" it too. In other
words, you need to create two Features to achieve a complete
Feature Stapling implementation. This means you can add your
"Custom Theme" feature to all publishing sites.
For Example: All newly created sites from "publishing site" site
definition should have your custom theme.
< Prev -
- Next >