In this article you will see how to implement Feature Stapling in SharePoint.
Scenario
I want a custom list to be created by default whenever a site is created using the Team Site template. The best way to do this is to create a Feature Stapling.
Feature Stapling
Feature Stapling can be created for the site definition that is already in use. Feature Stapling has two features.
- Stapler feature: staples another feature to the site definition
- Staplee feature: that which will be stapled
Steps involved
The following is the procedure steps to to implement Feature Stapling in SharePoint:
- Create Empty SharePoint Project
- Create a feature
- Create the feature stapler
- Create FeatureAssociation.xml
- Deploy the solution
- Check whether the feature stapler is activated in a web application
- Testing
Create Empty SharePoint Project
- Open Visual Studio 2010 by going clicking "Start" then select "All Programs" | "Microsoft Visual Studio 2010" then right-click on Microsoft Visual Studio 2010 and click on "Run as administrator".
- Go to the File tab, click on "New" and then click on "Project".
- In the New Project dialog box, expand the Visual C# node, and then select the SharePoint 2010 node.
- In the Templates pane, select "Empty SharePoint Project".
- Enter the Name as FeatureStapling and then click "OK".

- Enter the local site URL for debugging, select "Deploy as a farm solution" as in the following and then click on "Finish".

Create a feature
In this section you will see how to create a new feature and feature receiver to create a custom list in the site.
- In the Solution Explorer, right-click on the Feature folder and then click on "Add Feature".

- Rename the feature to "CreateListFeature".
- Double-click on the feature and enter the Title and Description for the feature.

- Select the scope as web from the drop down list.
- Right-click on CreateListFeature and then click on the Add Event receiver.

- Double-click on CreateListFeature.EventReceiver.cs and replace the code with the following:

- The code above creates a custom list on the feature activated.










Vinesh NagpalPosted Oct 9, 2015, 5:52 AM
Hi Vijay, thanks for your article.. When deploy the solution, i am getting error "FeatureSiteTemplateAssociation' are not supported at the 'Web' scope"
suhail ahmedPosted Nov 11, 2014, 1:08 AM
Hi Vijay. Thanks for sharing. Can you clarify is the GUID of feature(CreateListFeature) should be similar to TemplateId in Element.xml?
Md Qais AkhtarPosted Mar 12, 2014, 7:00 AM
Set FeatureStaple scope to "WebApplication"
Mahesh BabuPosted Jul 22, 2013, 2:36 PM
Hi Vijay, thanks for your article.. When deploy the solution, i am getting error "FeatureSiteTemplateAssociation' are not supported at the 'Web' scope"
Mahesh ChandPosted Jun 19, 2013, 10:59 AM
Welcome back Vijay