What is Feature Stapling In SharePoint 2010
Feature Stapling In SharePoint 2010
If you have created a site definition, there are several ways of using features with it. These are:
Include the features in the site definition (onet.xml) before using it to create sites.
Use feature stapling to associate your features to the site definition.
First option can be used only if the site definition is not deployed and no site is created using the site definition.
Second option should be used when the site definition is already in use (and sites have been created). This is because there are risks in modifying a site definition once it has been deployed, since the site definition files on the filesystem are used for pages which are ghosted (not modified).
To use feature-stapling, you first need the feature(s) you wish to link to the site definition - these should be created in the normal way. The, you should create a 2nd feature which does the actual stapling. Sample values for the various files are shown below:
The manifest.xml file if you are wrapping your feature in a solution:
<?xml version="1.0" encoding="utf-8"?>
<Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="26E1A1D9-7BB2-4e76-888E-B20184B16E3B">
<FeatureManifest Location="COB.Demos.FeatureStapling\feature.xml" />
The feature.xml file which defines the feature 'header' information:
<?xml version="1.0" encoding="utf-8" ?>
Description="Staples a set of features to custom site definitions. The features/site definitions are defined in stapling.xml."
<ElementManifest Location="stapling.xml" />
And finally, the core feature definition in the stapling.xml file:
<FeatureSiteTemplateAssociation Id="F6924D36-2FA8-4f0b-B16D-06B7250180FA" TemplateName="MySiteDefName#0" />
<FeatureSiteTemplateAssociation Id="94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" TemplateName="MySiteDefName#0" />
<FeatureSiteTemplateAssociation Id="02464C6A-9D07-4F30-BA04-E9035CF54392" TemplateName="MySiteDefName#0" />
The FeatureSiteTemplateAssociation element maps feature GUIDs to site defintions - note that the format of the TemplateName attribute value is <SiteDefName>#<ConfigurationID>. This obviously allows a degree of flexibility and allows you to do fairly complex things with different configurations of site definitions.
The final thing to note is that feature-stapling won't affect any sites which have already been created from a site definition, only subsequent sites. The only way to do this is to activate your features individually on the site, though obviously an STSADM script can help you activate multiple features against multiple sites.
8/2/2013 6:18:54 PM