Sunday, June 14, 2009

Understanding Feature Stapling

Hi All,

In this article, we will discuss something about feature stapling.

If I have to tell you in a very simple manner what we mean by feature stapling then my answer would be a feature that can attached to multiple site templates as well as multiple custom site templates at one go.

That means, let’s say we create one simple feature of creating list with few columns and if we want to have this list created every time blank site or team site is created, then we can register this feature to be used in team site and blank site, so that whenever we create team site or blank site, the list gets created.

If you want to have the feature available in every type of site templates then also you can do it. That means you select any templates then also that list will get created in it. We will call it as Global Site availability for the feature.

Here is a way we can achieve this.

Take a look at this XML. We will already have the feature that we want to have it in Team Site and Blank Site. So we will create one feature for achieving the feature stapling and its elements.xml is mentioned here.

<Elements xmlns=http://schemas.microsoft.com/sharepoint/>
<FeatureSiteTemplateAssociation
Id=”{GUID of the feature that you want to make available in Team Site and Blank Site}”
TemplateName=”STS#0” />

<FeatureSiteTemplateAssociation
Id=”{GUID of the feature that you want to make available in Team Site and Blank Site}”
TemplateName=”STS#1” />
</Elements>

Here STS#0 and STS#1 refer to Team Site and Blank Site respectively.

That is it, Deploy this feature and activates it at Site Collection level or site, web application or farm level.

From Next time, if you create the Team Site and Blank Site, the feature that you mentioned in stapling will be there in that site created.

If you want this feature to be there in every site template, then just one change you need to make and the change is as follows.

TemplateName attribute value will be “GLOBAL#0”. That’s it.

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com