Freigeben über


Feature Event Receiver

Specifies a server-side code routine that is called as part of four key events in the lifetime of a Feature: installation, activation, deactivation, and removal.

Real World Example

A developer creating a Feature determines that it must make some calls to the object model when activated, and perform some cleanup when deactivated. He creates a custom Feature event receiver class and includes a reference to it in the Feature definition.

Technical Details

You compile Feature event receivers into assemblies that are associated with the definition of a Feature. If a Feature receiver is associated with that Feature, when the Feature goes through one of its four lifecycle events it is called with additional information relating to the scope and target of that event.

The following feature.xml code example shows how the Feature receiver is registered as part of the feature definition:

<Feature   Id="39FA56C4-7A47-44F5-83CC-01B5E777F436" Title="Feature with Receiver Callback" Scope="Web" ReceiverAssembly="SimpleReceiver, Version=1.0.0.0, Culture=neutral, PublicKeyToken=207e2bf263eeeff6, processorArchitecture=MSIL" ReceiverClass="MS.Samples.SharePoint.SimpleProvisioner" xmlns="https://schemas.microsoft.com/sharepoint/" />

You can use Feature event receivers to perform additional setup or cleanup routines that core Feature activation and deactivation cannot perform, such as deleting files that the Feature installed into a site.

Support Details

Because a Feature event receiver can be called whenever the Feature is activated or deactivated, it can result in a delay associated with the event. Depending on the amount of code in the Feature event receiver, this could cause a significant delay if a new Feature is added to or removed from many locations at one time (for example, activating a Feature on every Web site within a very large SharePoint environment).