Feature Stapling in Sharepoint

Feature Stapling is a concept using which a specific feature will be stappled to site template.

What we gona acheive 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 stappling 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 Conetent Type.
2. Stapling Feature - The feature which will staple the "Stappled Feature" to specific Site template.

With Feature #1 : Stappled 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


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 Stappling Feature (Farm Scoped), and add the Stappling 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 Stappled Feature" will be automatically avaliable 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 Seperate WSP with new feature , instead of Feature Stapling. But each solution has a unique scenario which we will discuss the comaprision in next post.

Code Smaple: Downlaod Feature stapling.zip from skydrive folder.