1

This is my scenario:

I have one Web application with 2 site collections.

Then I have 2 lists ('list1' and 'list2' are in different site collections). The two lists however are identical (with the same columns, not data).

I have an Event Receiver which fires when an item in 'list1' is being updated.

What is the easiest way to add this exact Event receiver to 'list2', so that it fires when an item from 'list2' is updated as well?

1

There are couple of options for this.

  1. Create a custom list definition and attach the event handler to it. Then use this event handler to create the two lists.

  2. Create a content type and attach the event handler to content type. Then add that content type to both the lists.

  3. Programmatically attach the event handler.

    oWeb.Lists[_listName].EventReceivers.Add(SPEventReceiverType.ItemAdded, Assembly.GetExecutingAssembly().FullName,
        "EventReceiverProject1.EventReceiver1.EventReceiver1");
    
    oWeb.Lists[_listName].EventReceivers.Add(SPEventReceiverType.ItemUpdated, Assembly.GetExecutingAssembly().FullName,
        "EventReceiverProject1.EventReceiver1.EventReceiver1");
    
    oWeb.Lists[_listname].Update();    
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.