Binding a SharePoint Event Handler

You must associate your event receiver with a SharePoint object type (the event host), which you do by binding the event receiver to the receiver host.
There are two ways to bind an event receiver to a receiver host in Microsoft SharePoint Foundation 2010:

1.    By using the SharePoint Foundation object model.

Most of the primary SharePoint object types like SPWeb and SPList provide an EventReceivers property that allows the object to serve as an event host. The event receivers for each event host are contained in a collection, the SPEventReceiverDefinitionCollection, which contains all of the individual event definitions (SPEventReceiverDefinition) that are associated with the host.

Refer detail code sample:- Binding an Event Handler by Using the SharePoint Object Model

2.    You can also bind events to event hosts declaratively by using the Feature.xml file.

Using the Feature.xml approach allows you to create broad reaching event bindings and then deploy them easily as part of a solution package. You can bind an event handler for all announcements lists, for example, by using the list template identifier (ID); then, when the containing feature is activated, you can bind the event handler for any list of the specified type.
Alternatively, you can bind events declaratively by content type – for example, to bind an event handler for all documents of a specified type. Note that you can bind event receivers by using the XML for a given content type definition.

Refer detail code sample:- Binding Event Handlers by Using SharePoint Features.xml

Thanks!
Avinash

calendarMarch 21, 2012 · cardInfoyen · commentsNo Comments
tagTags:  · Posted in: Event Handler, List, MOSS, SharePoint, SharePoint 2010

Leave a Reply

Spam Protection: , required

myworldmaps infoyen