Feature Stapling is a concept using which a specific feature will be stapled to site template.
What we gonna achieve with it?
There will be scenario where certain resource has to be populated to every site collection that was / will be created on a farm.
Eg : I am dealing a client who is a owning a chemical lab. He want complete list of "Elements and their Atomic weights" to be present in every site that was already created, and any site that will be created in future.
In this scenario, Feature stapling will be used.
Lets see how to demonstrate it.
I have created a sharepoint project in which there are 2 features.
1. Stapled Feature - The feature taking care of creation of the Fields, a Content type and a List from that specific Content Type.
2. Stapling Feature - The feature which will staple the "Stapled Feature" to specific Site template.
With Feature #1 :
Stapled Feature (Site Scoped), LstContentType will be added to a site and a list called StapledList was getting created with default data i intended to create.
|
Stappled Feature Deployed and Activated |
|
LstContentType |
|
StapledList |
Add a element to project and i names it "
StaplingElement
". Modify the
elements.xml under
StaplingElement
and add the below XML tag to associate Stapled Feature to site template.
<featuresitetemplateassociation id="934cb12e-f397-41ff-be5a-7d32a085aff0" templatename="STS#0">
Now, create second feature #2 Stapling Feature (Farm Scoped), and add the Stapling Element.
Deploy the solution (WSP).
Go to
Central Admin =>
System Settings =>
Manage Farm Features => activate Stapling Feature.
Now, create a new Site Collection under a Existing / New Webapplication using
"Team Site" template.
The
"#1 Stapled Feature" will be automatically available in new site colection and will be activted. Thus all the above Fields, Content Type, List and its data will be automatically created by default.
How Feature stappling will effect the existing sites?
#1 Stappled feature will be added to exiting sites, but we need to enable the feature in all the existing sites using powershell or manually.
Many of the developers might think different solutions like
Custom Site Template,
Web Provisioning or
Separate WSP with new feature , instead of
Feature Stapling. But each solution has a unique scenario which we will discuss the comparison in next post.
Code Smaple: Downlaod Feature stapling.zip from skydrive folder.