Event Receivers in SharePoint Theory
Through this article I am trying to explain about event receivers in SharePoint.
An
event receiver is a class that contains one or more methods known as
event handlers that are executed automatically by SharePoint in response
to events such as adding item to a list.
You can use event handlers for data validation, data integrity etc.
SharePoint categories events into of two types 1. Before events (synchronous events) 2. After events (asynchronous events).
1. Before events (synchronous events):
These events fires before an action occurs and before SharePoint has written any data to the content database.
For
example ItemAdding event will fire when trying to add an item to a
list. These events does support cancelling of event action. These events
are always end with 'ing' like FieldAdding, ItemAdding, ItemUpdating,
WebAdding, WebDeleting etc. These events are also know as synchronous
events.
2. After events (asynchronous events):
These
events fire after the event action has completed and after SharePoint
Foundation has written to the content database to commit the event
action. These events does not support cancelling of event action. These
events does support cancelling of event action. These events are always
end with 'ed' like FieldAdded, ItemAdded, ItemUpdated, WebAdded,
WebDeleted etc. These events are also know as asynchronous events.
Events, Event Receivers & Object Model:
Event
receivers are nothing but custom classes which are derived from event
receiver base classes that are defined by Microsoft in
Microsoft.SharePoint assembly.
Some of the base classes are
SPItemEventReceiver: There are related to SharePoint items.
SPListEventReceiver: Related to lists.
SPWebEventReceiver: Related to webs.
SPWorkflowEventReceiver: Related to workflows instances. etc.
Remember all these classes(except SPEmailEventReceiver and
SPFeatureReceiver) are derived from a common base class know as
SPEventReceiverBase.
Here there are different event receivers:
Item-Level Event Receivers:
The base class for this type of event receivers are SPItemEventReceiver and are related to SPListItem instances.
Some
events are: ItemAdded, ItemAdding, ItemCheckedIn, ItemCheckingIn,
ItemCheckedOut, ItemCheckingOut, ItemDeleted, ItemDeleting etc.
List-Level Event Receivers:
The
base class for this type of event receivers are SPListEventReceiver and
events are related to lists. These events fires whenever any changes to
the fields of an existing list as well as adding or deleting list
instances.
Some events are: FieldAdded,
FieldAdding, FieldDeleted, FieldDeleting, FieldUpdated, FieldUpdating,
ListAdded, ListAdding, ListDeleted, ListDeleting etc.
Web-Level Event Receivers:
These
are events related to Site Collection deletion and website creation,
deletion, moving, and provisioning. The base class for these type of
event receiver is SPWebEventReceiver.
Some events are: SiteDeleted, SiteDeleting, WebAdding, WebDeleted, WebDeleting, WebProvisioned etc.
Workflow Event Receivers:
These
event receivers are for running workflows and the base class for these
type of event receivers are: SPWorkflowEventReceiver.
Some events are: WorkflowStarting, WorkflowStarted, WorkflowCompleted etc.
E-Mail Event Receivers:
These event receivers are for e-mail–enabled list instances and the base class is SPEmailEventReceiver.
For this type of event receivers you have to override the EmailReceived method.
Comments
Post a Comment