Answered by:
Event Receiver For A Single Custom List

Question
-
I had a custom list in sharepoint and i want to create an eventreceiver and work with its events. i went to visual studio and there is a option to create event receiver for custom list only. but i have 4 custom list and i want the event receiver for only one custom list through which i want to copy the items. There should be a quick solution but i am not getting anyone can help me pleaseThursday, October 15, 2009 5:44 PM
Answers
-
You can bind the event receiver to a specific list using a Feature Receiver. You need to write a cleas which inherits SPFeatureReceiver and implement the FeatureActivated method. Here's example code for the FeatureActivated method which adds the event receiver to the "Rating History" list.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
web.Lists["Rating History"].EventReceivers.Add(
SPEventReceiverType.ItemAdded,
"Dhunter.SharePoint.Eventhandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a26195ff03df1fd",
"Dhunter.SharePoint.Eventhandlers.RatingSummaryEventHandler");
}
With the event receiver you write the class to implement your business logic and deploy to the GAC. You don't need a feature xml for the event receiver as the binding is handled by the feature receiver.
Hope this helps
Dave
My SharePoint Blog - http://www.davehunter.co.uk/blog- Marked as answer by Aaron Han - MSFT Wednesday, October 21, 2009 4:05 AM
Friday, October 16, 2009 9:31 AM -
Hi Kukdai,There are many ways to do this. The best approach is to creating a custom content type with event handlers which can be added a specific list. Please see below article to understand more about this.
Sharepoint Consultant- Marked as answer by Aaron Han - MSFT Wednesday, October 21, 2009 4:05 AM
Thursday, October 15, 2009 7:26 PM
All replies
-
Hi Kukdai,There are many ways to do this. The best approach is to creating a custom content type with event handlers which can be added a specific list. Please see below article to understand more about this.
Sharepoint Consultant- Marked as answer by Aaron Han - MSFT Wednesday, October 21, 2009 4:05 AM
Thursday, October 15, 2009 7:26 PM -
You can bind the event receiver to a specific list using a Feature Receiver. You need to write a cleas which inherits SPFeatureReceiver and implement the FeatureActivated method. Here's example code for the FeatureActivated method which adds the event receiver to the "Rating History" list.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb;
web.Lists["Rating History"].EventReceivers.Add(
SPEventReceiverType.ItemAdded,
"Dhunter.SharePoint.Eventhandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a26195ff03df1fd",
"Dhunter.SharePoint.Eventhandlers.RatingSummaryEventHandler");
}
With the event receiver you write the class to implement your business logic and deploy to the GAC. You don't need a feature xml for the event receiver as the binding is handled by the feature receiver.
Hope this helps
Dave
My SharePoint Blog - http://www.davehunter.co.uk/blog- Marked as answer by Aaron Han - MSFT Wednesday, October 21, 2009 4:05 AM
Friday, October 16, 2009 9:31 AM