There are two scope considerations when creating and deploying Features. The first consideration is the scope of the Feature itself-that is, whether the Feature is made available to a server farm, Web application, site collection, or site (or Web). The second consideration includes any elements you will use in the Feature and the scope of those elements. For instance, some elements, such as a Content Type element, can only be used in a site-scoped Feature whereas other elements, such as a Custom Action element, can be used across all Feature scopes‥
Feature scope is defined in the Feature.xml file, using the Scope attribute. Once a Feature is installed, the SharePoint Server 2007 administrative user interface includes the ability to administer Features for given scopes, as shown in Table 26-3. This includes the ability to activate and deactivate Features.
Feature scope | Description | Administration UI path |
---|---|---|
Farm (denoted by Farm) | Specific to farm-level administrative tasks, such as application management. Farm-level Features are activated by default. | SharePoint Central Administration, Operations, Global Configuration, Manage Farm Features |
Web Application (denoted by WebApplication) | Specific to Web application or virtual server requirements, such as Search | SharePoint Central Administration, Application Management, SharePoint Web Application Management, Manage Web Application Features |
Site Collection (denoted by Site) | Specifies items that relate to an entire site collection, such as Web Parts or content types | Parent (or root) site of site collection, Site Settings, Site Collection Administration, Site Collection Features |
Web or Site (denoted by Web) | Items that are specific to individual Web sites, such as list templates | Site, Site Settings, Site Administration, Site Features |
Activation and deactivation of Features is not limited to the administrative user interface. You can also use Feature activation and deactivation through the stsadm.exe command-line tool, through the SharePoint object model, and by deploying the Feature as part of a site definition. The "Deploying Features" section of this chapter describes the deployment options. You will learn how to deploy a Feature as part of a site definition in the "Including Features in Site Definitions" section.
Figure 26-2 shows Features scoped at the farm level and visible in the administrative user interface page that can be activated and deactivated.
Figure 26-2: Farm-scoped Features shown in the administrative user interface
Note | If a Feature is Hidden, it will not be visible in the administrative user interface. Farm-scoped Features, when installed, are activated by default. |
Not all elements are available at all scope levels. For example, the Custom Action element, which defines actions such as a link or additional toolbar button, is available at all Feature scope levels, whereas the Content Type element is available only within the scope of a site collection. A list of elements and respective scope allocation can be found in Table 26-4, and additional information concerning element scopes can be found in the Windows SharePoint Services 3.0 Software Development Kit on the Microsoft Download Center.
Scope | Element |
---|---|
Farm | Control |
Custom Action | |
Custom Action Group | |
Document Converter | |
Feature/Site Template Association | |
Hide Custom Action | |
Web Application | Control |
Custom Action | |
Custom Action Group | |
Document Converter | |
Feature/Site Template Association | |
Hide Custom Action | |
Site Collection | Content Type |
Content Type Binding | |
Control | |
Custom Action | |
Custom Action Group | |
Feature/Site Template Association | |
Field | |
Hide Custom Action | |
List Instance | |
Module | |
Workflow | |
Web or Site | Content Type Binding |
Control | |
Custom Action | |
Custom Action Group | |
Feature/Site Template Association | |
Hide Custom Action | |
List Instance | |
List Template | |
Module | |
Receiver |
In addition, Table 26-4 lists elements available for a given Feature scope. For example, to deploy Content Types as part of your Feature, you need to scope your Feature for a site collection by using the Scope attribute in the Feature.xml file because deploying Content Types to a Web-scoped Feature is not supported. You would set the attribute as Scope="site", where site is the site collection.
Here is an example of adding a simple site column to a site using a Feature. Both the Feature.xml and Elements.xml files are included. The Feature must be scoped to Site, as in a site collection, because this is the only scope to which you can deploy the Field element that is included in the associated Elements.xml file.
Feature.xml File
<?xml version="1.0" encoding="utf-8" ?> <Feature xmlns="http://schemas.microsoft.com/sharepoint/" Id ="" Title="Project Vision Field" Description =" A Field for Project Vision." Scope="Site"> <ElementManifests> <ElementManifest Location="Elements.xml" /> </ElementManifests> </Feature>
Elements.xml File
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Field DisplayName="Project Vision" Type="Text" Required ="TRUE" Name="ProjectVision" RowOrdinal="0" ReadOnly="FALSE" Group="Project Field" /> </Elements>