Understanding SharePoint Features

First… What Is a Feature?

A feature is a mechanism to deploy and activate customizations to a SharePoint environment. Features can be activated in the user interface empowering the administrator or end user with the ability to easily enable or disable a customization. Features are made of a manifest or feature.xml, one or many additional element XML files and additional resource files if applicable. Read more at MSDN. The most important benefit to features is that they can be deployed with Solution Packages (WSP), using solution packages will keep you in a supported, restorable state and encourages developers to focus on deployment and packaging during the initial phases of development which is extremely important.

What Can I Install With Features?

The Feature.xml File

You can drill into the entire schema of the feature.xml file by reading the Feature.xml Files article at MSDN. We’re going to cover the important parts and talk about how to utilize features effectively.

Scope

Scope allows you to decide where this feature will be available for activation. This is a very powerful concept. For example, you could activate a new list template per sub site (scoped to the Web) or activate it once for the entire site collection (scoped to the Site).

Farm

Displays under Central Administration > Operations


Farm level features are useful for installing things such as configuration screens that might apply for the entire farm or the initial installation of a custom application built on SharePoint.

WebApplication

Displays under Central Administration > Application Management

Web application level features are useful for installing timer jobs as timer job are always scoped to run at the Web Application level.

Site (Site Collection)

Displays under Site Action > Site Settings > Site Collection Settings (or Site Settings if currently on the root site)

Web (Sub Site)

Displays under Site Actions > Site Settings

Activation Dependencies

Here’s an example of the activation dependencies node.

A good example of of an activation dependency is when you might have one feature install Site Columns and a second feature install the Content Types. SharePoint uses activation dependencies for activating publishing functionality. If you attempt to activate publishing at the web level without first activating publishing at the site collection level you will receive the following error message:

Element Manifests

The element manifest is used to include both individual resource files such as images, css files, master pages, page layouts and element files which tell SharePoint where to copy files or what to configure once the feature was activated.

The element manifest is where the work gets done. Read about what you can install with features for the full list of possiblities.

Custom Properties

By defining properties within your feature XML you can make your features configurable and use those configuration properties in your feature activation code. The feature properties XML looks like this:

<Properties>
    <Property Key="Color" Value="Blue"/>
    <Property Key="Shape" Value="Triangle"/>
</Properties>

Here’s how you utilize these feature properties in your feature activation code:

public override void FeatureActivated(SPFeatureReceiverProperties properties) {
    string colorProperty = properties.Feature.Properties["Color"].Value;
    string shapeProperty = properties.Feature.Properties["Shape"].Value;
// main code here
}
I'm a public speaker and the Chief SharePoint Architect for Eastridge, a Microsoft Gold Partner specializing in SharePoint and custom application development in Winston-Salem, NC. I focus on the SharePoint platform with a specialty in Information Architecture, Publishing and Best Practices.

Got something to say? Go for it!