locked
what is best practice for custom eventhandler RRS feed

  • Question

  • hi

    I had created one event handler on one site having code for all lists events.

    This event handler execute  for all the events of every list.

    Is this is good practice to execute one event handler for all list?

    or we have to create eventhandler for every list?

     


    Thanks & Regards, Vyankatesh Mujumdar
    Thursday, February 17, 2011 12:21 PM

Answers

  • Hello David,

    You had provided very good information.

    Means What we had done is also acceptable.

    We have 10-15 custom list .And every list have something update at the time of adding and updating . So in eventhandler instade of crating multiple eventhandler we had created one event handler and added cases on list name.

    like in

     Item Adding()

    {

    case list1name:

    //code

    break;

    case list2name:

    //code

    break

    }

    and this is working fine.

    I think this is also one of the good practice.

    Is it?


    Thanks & Regards, Vyankatesh Mujumdar
    • Marked as answer by David HM Friday, February 25, 2011 9:23 AM
    Monday, February 21, 2011 6:40 AM

All replies

  • Please go through this article, this will satisfy you

    Event Receivers


    w: http://www.worldofsharepoint.com | t: @sharesandip
    Thursday, February 17, 2011 1:34 PM
  • Hi Vyanku,

     

    As you are aware that you can attach an event handler for all the list in the site & also for a specific list instance, it depends upon your requirement.

     

    For example, if you are having columns A & B and in your event handler based on some condition you are updating a column C with (A+B/A-B).

    This, surely is a list specific event handler action & should not be attached for all the lists in the site.

     

    Thanks,

    Chanakya

    Friday, February 18, 2011 9:09 AM
  • Hi,

     

    According to your description, you want to create event handler for all lists or every list. In Windows SharePoint Service 3.0, there are three fundamental ways to register an event handler:

    1.        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.

    2.        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.

    3.        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.

    Here are a good example of binding an event handler by using the SharePoint Object Model and creating a list Event handler, please refer to:

    http://msdn.microsoft.com/en-us/library/ff407249.aspx#Y601

    http://msdn.microsoft.com/en-us/library/ms437502.aspx

     
    Best regards
    David Hu

     

    Monday, February 21, 2011 5:53 AM
  • Hello David,

    You had provided very good information.

    Means What we had done is also acceptable.

    We have 10-15 custom list .And every list have something update at the time of adding and updating . So in eventhandler instade of crating multiple eventhandler we had created one event handler and added cases on list name.

    like in

     Item Adding()

    {

    case list1name:

    //code

    break;

    case list2name:

    //code

    break

    }

    and this is working fine.

    I think this is also one of the good practice.

    Is it?


    Thanks & Regards, Vyankatesh Mujumdar
    • Marked as answer by David HM Friday, February 25, 2011 9:23 AM
    Monday, February 21, 2011 6:40 AM