Monday, July 19, 2010

Introduction

What are Event Receivers?

SharePoint 2007 Event Receivers are a type of feature which listens for certain events on a site, list or list item. Event Receivers are the MOSS version of document event handlers (also known as Event Sink) in SharePoint V2 technologies (WSS and SPS). Previously the document event handlers were only available for document libaries. Event receivers are now available for any type of list.

What can they be used for?

SharePoint 2007 Event Receivers add behaviours to lists or list items. They are commonly used to perform data validation (beyond SharePoint standard capabilities), to ensure data integrity or to perform a business process.

Definition

Event Receivers have before and after events.

The events relating to a site are:
Before
SiteDeleting
WebDeleting
WebMoving
After
SiteDeleted
WebDeleted
WebMoved
A class needs to inherit from SPWebEventReceiver. The behaviour is defined by overriding a method for one of the above before or after events. You can access properties that relates to the event that the feature is listening using SPWebEventProperties.

The events relating to a list are:
Before
FieldAdding
FieldUpdating
FieldDeleting
After
FieldAdded
FieldUpdated
FieldDeleted
A class needs to inherit from SPListEventReceiver. You define the behaviour by overriding a method for one of the above before or after events. You can access the event properties using the parameter SPListEventProperties.

The events releating to list items are:

Before
ItemAdding
ItemUpdating
ItemDeleting
After
ItemAdded
ItemUpdated
ItemDeleted
ItemAttachmentAdded
ItemAttachmentDeleted
ItemCheckedIn
ItemCheckedOut
ItemFileConverted
ItemFileMoved
ItemUncheckedOut
A class needs to inherit from SPItemEventReceiver. You then override a method for one of the above before or after events. The event properties can be accessed by the local parameter SPItemEventProperties. One of these is the list item. For example:


public override void ItemAdded(SPItemEventProperties properties)
{
SPListItem currentListItem = properties.ListItem;
// other implementation here .....
}

Other important information of the properties object is the AfterProperties and BeforeProperties. AfterProperties provide access to the modified properties. BeforeProperties provide access to the column data before it was changed. This enables you to perform changed based validation.

No comments:

Post a Comment

Content Editor Webpart not showing up in SharePoint Online ------------------------------------------------------------------------------...