Associate Event Handlers in SharePoint to specific list

In Windows SharePoint Services 3.0, there are three fundamental ways to register an event handler:

  • Through the object model, as the SPWeb and SPList classes now each provide an EventReceivers property through which to access the collection of event receiver definitions for the Web site or list. You can add new event receivers by calling the Add method.
  • Declaratively by list type, for example, to register an event handler for all announcements lists. In a Feature.xml file, you can register an event handler by list template ID. When the containing feature is activated per SPWeb object, you can register the event handler for any list of the specified type.
  • Declaratively by content type, for example, to register an event handler for all documents of a specific type. Within the XML for a content type definition, you can register event receivers.

So if you need to make your list event handler specific to list then,

  1. Create a custom list type using a list definition and then attach the event handler to it
  2. Create a custom content type for your list and attach the event handler to the content type, this will make the event handler specific to list
  3. Register the event handler using object model to the list you desire. You can us e this free tool which facilitates this (http://www.u2u.info/SharePoint/U2U%20Community%20Tools/EventHandlerExplorer.zip)
  4. Check for the list in the event handler code before executing the code.

Related Post

1 thought on “Associate Event Handlers in SharePoint to specific list”

Leave a Reply

Your email address will not be published. Required fields are marked *