Thursday 19 January 2012

Deploy Event receiver for a specific list or library in SharePoint 2010


There are several ways to do this.

Option 1 - Specify the list template id in your elements file.
This is the most adoped way to attach an event receiver with a specific list.
All you have to do is to create a new list template that will be associated with the your event handler via your elements.xml file. Once done you will have a new list template available and the list made out of it would have the event receiver attached.

You can same way create a content type instead of a list template and associate the content type with your Event reciver. The receiver will then run on a specific content type where ever its used in the site.

Option 2 -
Second option is to attach the event receiver using the Fetaure receiver file.
All you have to do is add a new feature receiver in your solution and then
add the below in FeatureActivated.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
web.Lists["SomeList"].EventReceivers.Add(SPEventReceiverType.ItemAdded, "namespace Version=1.0.0.0, Culture=neutral, PublicKeyToken=a3a26195fk03df1fd","namespace.eventreceiver_classname");
}
ref - http://www.learningsharepoint.com/forum/sharepoint-2010-programming/deploy-event-receiver-to-specific-list-2010/

Ads by Google

No comments:

Post a Comment