Archive for the ‘Windows Sharepoint Services 3.0’ Category

Feature stapling – why and how?

15. October 2009

Have you ever been in a situation where you needed to modify an existing site definition like the Team site? Editing the files in the 12-hive is not an option since a lot of sites are already based on this site definition, and changing the ONET.XML could influence on existing sites.

The answer is feature stapling, a simple way to write a feature and associate it to every site that is to be create based on your site definition, and to make a feature that e.g. makes an extra link in the site actions menu to http://www.qwert.dk, we need to go through the following steps:

  1. Create the feature that makes the link
  2. create the stapling-feature and activate it

And now…..in a bit more details.

First step is to make a feature that creates the link, so open up Visual Studio, create a new project and create a feature with an elements-file that could look like this:

Elements code

Elements code

To install it you need to use the Sharepoint-toy of them all - stsadm, and an amazing stsadm -o installfeature -name [the name of your feature folder] will install the feature in the farm.

To create the stapling-feature you actually have to make another feature and scope it at the farm-level – in this manner every web created from this site definition will have the feature activated. The feature should look something like the following:

Stapling_FarmFeature

Note that it is a Farm-scoped feature and it has an elementmanifest with a location of elements.xml – so let’s take a look at the elements-file and the stuff it is containing:

 

Staple_Elements

The FeatureSiteTemplateAssociation has an ID attribute which is obviously the ID of the link-feature and then a template-name which is the name of the folder it is situated in a # and then the ID of the configuration in that folder.

Actviate it in the Cetral Administration under Farm Features and BOING your link-feature will be activated every time you create a new blank site. If you wanted to staple a feature for all sitedefinitions in the farm you could put GLOBAL as the value of the TemplateName-property. This will hit every sitedefinition in the farm.


Follow

Get every new post delivered to your Inbox.