Compartilhar via


Building Block: Event Handling

Applies to: SharePoint Foundation 2010

The primary objects in the SharePoint Foundation object model provide event receiver base classes from which to derive when writing event handlers. For example, The SPWeb object has a corresponding SPWebEventReceiver type, the SPList object has a SPListEventReceiver type, and so forth. You do not implement the event receiver types directly; rather, you should inherit from the appropriate receiver class and implement the derived class. Note that all SharePoint event receiver classes inherit from a single event receiver base class, which is SPEventReceiverBase.

After they have been written, event receivers for SharePoint Foundation are compiled into event receiver assemblies and deployed to the global assembly cache (GAC). Event receivers must also be registered at the scope for which they handle events.

Object Model for Events

There is no event handler namespace in which event handler types are located. Rather, event handlers are located in the same namespace as their associated SharePoint objects. For example, all of the top-level SharePoint objects (SPWeb, SPSite, SPList, and so on) are located in the Microsoft.SharePoint namespace along with their associated event receiver types. Note that the naming convention for event receiver types follows the familiar pattern described above – that is, <object name> with the term "EventReceiver" added as a suffix. In this way, event receiver types like SPWorkflowEventReceiver and StyleLibraryEventReceiver are easy to identify and understand.

Warning

There are some exceptions to the event receiver naming rule. For example, the event receiver for SharePoint Features is named SPFeatureReceiver, not SPFeatureEventReceiver as might be expected.

Event receiver types are also associated with event property bags that provide access to various properties of a specified event. Event property bags are typically named <object name> with the term "EventProperties" added as a suffix. Typical event receiver property bags are SPWebEventProperties, SPListEventProperties, and so forth.

Documentation for Working with SharePoint Events