This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
Windows SharePoint Services 3.0 provides classes for responding to Feature events, which allow you to trap and respond to an event that fires when a Feature is installed in the server farm, when a Feature is added to a new virtual server, or when a Feature is removed.
Some of these events are post events, meaning that they fire after the respective behavior has been committed and the Feature definition is created in the collection of Feature definitions for the farm.
It is not possible to cancel an installation or uninstall operation through Feature events.
Microsoft.SharePoint.SPFeatureReceiver Base abstract class that can be overridden to trap the activation, deactivation, installation, or uninstall operation of a Feature. Namespace: Microsoft.SharePoint
Microsoft.SharePoint.SPFeatureReceiverProperties Class that provides access to event properties, such as the Feature instance that has been created, the Feature definition, or the parent object of the Feature; for example, a Microsoft.SharePoint.SPWeb object. Namespace: Microsoft.SharePoint
Feature provisioning callouts allow you to write specific code to handle various events that transpire in the lifecycle of a Feature. The SPFeatureReceiver class provides the following methods for handling events:
To implement provisioning callouts, create a class that derives from SPFeatureReceiver and implements these methods.
You are always passed the pointer to your parent object (such as a parent SPWeb), so you can customize as needed.
The assembly that contains a Feature receiver must be located in the global assembly cache (GAC). In the Feature.xml file, you can register a Feature receiver through the ReceiverAssembly and ReceiverClass attributes of the top-level Feature element, for example:
<Feature Id="5E88AE4E-2ECB-4CC5-B9EC-9019250F5BC8" Title="Knowledge Base Infrastructure" Scope="Site" ReceiverAssembly="MS.Samples.SharePoint.KnowledgeBase, Version=126.96.36.199, Culture=neutral, PublicKeyToken=d24e3c1752ded9ed" ReceiverClass="MS.Samples.SharePoint.KnowledgeBase.KnowledgeBaseInstaller" xmlns="http://schemas.microsoft.com/sharepoint/">
Any exceptions thrown during the activation process are communicated to the user, and the Feature is not marked as activated.
Write code that handles cases where a user attempts to force activation of your Feature even though it is already activated. For example, if your Feature callout creates a list, verify that your code does not fail if the list already exists.