Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Multiple events handlers in same web on different lists of same type

  Asked By: Tyrel    Date: Dec 07    Category: Sharepoint    Views: 1222

I have 4 document libraries in the same web. I would like to use a
different event handler on each document library.

I remebember hearing that when a event hanlder is activated as feature,
it bound to all lists types as defined in the elements file for the
feature?

Is this true? If so, how does on get around it, other than creating one
event handler with a switch that determines what document library was
hit, and running a specific routine depending on the switch?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Josie Barron     Answered On: Dec 07

Unfortunately, event handlers  are scoped at the SPWeb level. There are
two ways I know of to handle this.

1. In the FeatureActivated event, apply the event  handlers to the
appropriate lists. I don't have sample code to show this.

2. Code the event handler  and execute code based on which list (or
document library) it occurred to. Here's an example of the ItemAdded
event:

public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);

// Prevent the accidental triggering of events  from logic
executed in this method.
this.DisableEventFiring();

// Get the List Name in which this event was triggered.
string strListName = properties.ListTitle;

try
{
switch (strListName)
{
case "Courses": this.ItemAddingCourses(properties);
break;
case "Course Category":
this.ItemAddingCourseCategory(properties); break;
default: break;
}
}
catch (Exception ex)
{
properties.ErrorMessage = ex.Message + " " +
ex.StackTrace;
properties.Cancel = true;
}


// Re-Enable event trigggering
this.EnableEventFiring();
}

 
Answer #2    Answered By: Tamika Cummings     Answered On: Dec 07

You can associate an event  to a specific  list, see this:

claytonj.wordpress.com/.../
by using the OM.

 




Tagged: