16.6 Feature Stapling 491
Chapter 16
another Feature, and no additional Features depend upon that Feature, then
both Features are automatically deactivated.
Additionally, when you deactivate a Feature, the functionality that the
Feature provided is removed from the area in which the Feature was deacti-
vated. For example, when we deactivate our HelloWorld Feature, the Hello
World action disappears from the Site Actions menu.
16.5.5 Uninstalling a Feature
Features are uninstalled using the uninstallFeature operation of the
stsadm.exe command line utility. Figure 16.23 shows the command required
to uninstall our HelloWorld Feature; you can specify either the name of the
Feature folder, using the –
name switch, or the path to the Feature.xml file,
using the –
filename switch.
When a Feature is uninstalled, the Feature definition is removed from
the
Objects table within the SharePoint configuration database.
16.6 Feature Stapling
Feature stapling allows you to associate, or staple, Features to an existing site
definition or custom site definition. For example, if you had a custom Fea-
ture that set the master page, the cascading style sheet, and the theme to
custom settings, and you wanted these settings to apply when a site was cre-
ated using a specific site definition, then you would use a Feature staple to
staple your custom Feature to that site definition. A Feature staple is itself a
Figure 16.21
Deactivate Feature
using browser UI.
Figure 16.22
deactivateFeature
command.
Figure 16.23
uninstallFeature
command.
492 16.6 Feature Stapling
Feature; it comprises a Feature folder, a Feature definition file, and an ele-
ment manifest file. The element manifest file uses the
FeatureSiteTem-
plateAssociation
element to associate the Feature with a specific site
definition. The
FeatureSiteTemplateAssociation element has two
attributes:
Id and TemplateName. The Id attribute must map to the ID of
an existing Feature, and the
TemplateName attribute is used to specify the
site definition configuration (site template) to which the Feature will be sta-
pled. Figure 16.24 shows an example of a Feature staple that staples a brand-
ing Feature to the site SpysRUs site template. If you want to make your
Feature available to all newly created sites, regardless of the site definition
from which they were created, you can staple your Feature to the GLOBAL
site definition. Figure 16.25 shows an updated version of the element mani-
fest used in our previous example; the
TemplateName has now been replaced
with the GLOBAL setting. Note that you do not need to specify a configu-
ration number when stapling to the GLOBAL site definition.
As you can see, Feature stapling allows you to staple a Feature to exist-
ing site definitions, even the typically untouchable Microsoft-generated site
definitions. This ability provides an extremely easy way of adding additional
functionality and customizations without having to reproduce an entire site
definition. Feature stapling provides easier manageability and maintainabil-
Figure 16.24
Feature stapling.
Figure 16.25
StapleSites.xml
Get Microsoft SharePoint 2007 Technologies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.