Friday, July 30, 2010

Why Feature stapling in SharePoint

sometimes you may want to attach your feature with site definition i.e. whenever someone create a site using particular site definition you might want to activate the feature by default, and in same scenario it may be possible that you do not own the site definition hence cannot modify the existing site definition to attach feature (like SharePoint default site def e.g. team site\publishing\collaboration).

In these cases you can write a feature and can attach the feature itself with the site definition.

From MSDN :
"Causes the attachment of a Feature to all new instances of sites that use a given site definition, without modifying the site definition or creating code routines to activate the Feature on each site. Also known as a feature site template association"

Following is an example of feature stapling that associates the Feature with only the STS site definition template

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation Id="00BFE171-1B17-4F72-28CB-1171C0140130" TemplateName="STS#0" />
</Elements>

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/5e27a15b-5ceb-4706-b660-aadad03e0f3c