Ads

Monday, 8 July 2013

SharePoint 2010 Feature Stapling

Feature Stapling allows you to create a feature and then associate it with any site definition without ever touching the site definition files themselves. Your feature will be activated when the site is provisioned.

Stapling basically consist of two features:
  1. Staplee Feature: The feature which will be stapled to an existing site definition
  2. Stapler Feature: The feature which will staple the staplee feature with site definition

Steps

  1. Create new Empty SharePoint Project.
  2. Create staplee feature which we want to get activated on site provisioning.
  3. Create Stapler feature with scope as Farm.
  4. Add new Empy Element "StaplerElementHelper" to the project.
  5. Edit Element.xml file
  6. Add follwing line<FeatureSiteTemplateAssociation Id="d3f566c2-b711-4ddb-808b-c4d0c00dac36" TemplateName="STS#0" />FeatureSiteTemplateAssociation is going to associate our steplee feature with site definition "STS#0"(team site).
    Note: Replace value of Id with your staplee feature ID. You can also specify your own TemplateName.

    your complete file will look like
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/"><FeatureSiteTemplateAssociation Id="d3f566c2-b711-4ddb-808b-c4d0c00dac36" TemplateName="STS#0" />
    </Elements>
  7. Double click your Stapler Feature and Include "StaplerElementHelper" in "Items in feature". Remember it should be included in Stapler feature and not in staplee feature.
  8. Deploy it.

Now whenever you create a new site using site definition specified in FeatureSiteTemplateAssociation staplee feature will automatically get activated.

Sample Project

refer click 

No comments:

Post a Comment

Ads