locked
Event Receiver is Firing on All Document Libraries RRS feed

  • Question

  • I create Custom List Difintion with ID 10101

    I create Event receiver on the List Item on this List

    on Item Updating

    but this event is firing for all Document Library not only for the one of the Custom List Difintion

    Feature Scope is Site

    any Help Please

    <Receivers ListTemplateId="10101">

    The important thing is not to stop questioning - Albert Einstein


    • Edited by Fadi Nassri Tuesday, November 20, 2012 6:15 AM
    Tuesday, November 20, 2012 6:14 AM

Answers

  • Hi,

    Try  change scope feature to WEB.  ListTemplateId seems to be ignored for Site scoped features.

    NicoBzh

    • Marked as answer by Qiao Wei Friday, November 30, 2012 9:47 AM
    Tuesday, November 20, 2012 7:50 AM
  • Hi Fadi,

    Please have a look on this link http://msdn.microsoft.com/en-us/library/ff398052(v=vs.100).aspx

    Also, The following code snippet shows the elements.xml file for an event receiver for a custom list.

    Basically there are three more attributes added for <Receivers> element and those are:
    Scope: we can define the scope of Event Receiver to SiteCollection (Site) or Web level
    RootWebOnly: event receiver will be attached to all lists under root web created using particular template
    ListUrl: we can specify particular list on which Event Receiver will be active (/Lists/MyList/)

    <Receivers ListTemplateId="1066" ListUrl="/Lists/MyList/"> <Receiver> <Name></Name> <Type></Type> <Assembly></Assembly> <Class></Class> <SequenceNumber></SequenceNumber> </Receiver> </Receivers>

     

    Alternatively, you may attach event receiver using Eventreceiver Feature code behind:

    [Guid("58bc2040-cc75-4604-ae17-7cda078c6947")] public class MyTestEventReceiver : SPFeatureReceiver { // Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site= properties.Feature.Parent as SPSite; //feature scopt site site.RootWeb.Lists["MyTestList"].EventReceivers.Add(SPEventReceiverType.ItemAdded, "MyTest.EventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8f1f998b2840e73a", "MyTest.EventHandler.Mytest.MyTestList"); } }

    Hope this helps:)

     

    Regards

    Sushil

    • Proposed as answer by Mahindrakar Tuesday, November 20, 2012 1:02 PM
    • Marked as answer by Qiao Wei Friday, November 30, 2012 9:47 AM
    Tuesday, November 20, 2012 7:42 AM

All replies

  • Hi,

    Please mention the Url of your document library URL in "elements.xml".

    For example if i want to execute my event reciver on "ABC" list ,i will update

    <ReceiversListUrl="Lists/abc">

    Hope this helps.

    Let me know if you have any queries .

    Mark as answer if it solves your problem .


    "The Only Way To Get Smarter Is By Playing A Smarter Opponent"

    • Proposed as answer by Rahul A Shinde Tuesday, November 20, 2012 6:58 AM
    • Unproposed as answer by Fadi Nassri Tuesday, November 20, 2012 7:34 AM
    Tuesday, November 20, 2012 6:40 AM
  • Thanks Dear but this is not what I need

    I have many Document Libraries created from the Custom List Difintion not only one

    I need the event Recevier to work on all Libraries of that Type


    The important thing is not to stop questioning - Albert Einstein

    Tuesday, November 20, 2012 7:34 AM
  • Hi Fadi,

    Please have a look on this link http://msdn.microsoft.com/en-us/library/ff398052(v=vs.100).aspx

    Also, The following code snippet shows the elements.xml file for an event receiver for a custom list.

    Basically there are three more attributes added for <Receivers> element and those are:
    Scope: we can define the scope of Event Receiver to SiteCollection (Site) or Web level
    RootWebOnly: event receiver will be attached to all lists under root web created using particular template
    ListUrl: we can specify particular list on which Event Receiver will be active (/Lists/MyList/)

    <Receivers ListTemplateId="1066" ListUrl="/Lists/MyList/"> <Receiver> <Name></Name> <Type></Type> <Assembly></Assembly> <Class></Class> <SequenceNumber></SequenceNumber> </Receiver> </Receivers>

     

    Alternatively, you may attach event receiver using Eventreceiver Feature code behind:

    [Guid("58bc2040-cc75-4604-ae17-7cda078c6947")] public class MyTestEventReceiver : SPFeatureReceiver { // Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site= properties.Feature.Parent as SPSite; //feature scopt site site.RootWeb.Lists["MyTestList"].EventReceivers.Add(SPEventReceiverType.ItemAdded, "MyTest.EventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8f1f998b2840e73a", "MyTest.EventHandler.Mytest.MyTestList"); } }

    Hope this helps:)

     

    Regards

    Sushil

    • Proposed as answer by Mahindrakar Tuesday, November 20, 2012 1:02 PM
    • Marked as answer by Qiao Wei Friday, November 30, 2012 9:47 AM
    Tuesday, November 20, 2012 7:42 AM
  • Hi,

    Try  change scope feature to WEB.  ListTemplateId seems to be ignored for Site scoped features.

    NicoBzh

    • Marked as answer by Qiao Wei Friday, November 30, 2012 9:47 AM
    Tuesday, November 20, 2012 7:50 AM