Eventreceiver on a single custom list RRS feed

  • Question

  • I am running Sharepoint foundation 2010, and have created a eventreceiver projet in VS2010. I choose "Custom list" to fire an event to my one of my custom lists. But I can't choose which custom list I want to add the event to, how can I select a single custom list instead of all custom lists?

    //Jesper, Denmark

    Tuesday, September 28, 2010 10:55 AM


All replies

  • you can't filter an event receiver down to a single custom list unless you write your own activator.  Event Receivers activated by a Feature will always fire on all the lists of a particular type that you specify, in this case a custom list.  You have two options.

    1) write code to instantiate your event reciever on a specific list instead of using a feature which will activate it on all lists of a specific type.

    2) Let the event receiver fire on all custom lists and then add code to the receiver itself to ignore the event on all lists except the one you want to use it on.

    #2 is easier, but less efficient.

    Paul Stork SharePoint Server MVP
    Tuesday, September 28, 2010 12:10 PM
  • This is true for 2007, but 2010 adds support for the ListUrl attribute in the Receivers element. Is it instead of ListTemplateId (populated by VS when you pick the list type) in your element manifest as ListUrl='Lists/MyCustomList'.

    Here's a link! http://msdn.microsoft.com/en-us/library/ms431081.aspx


    Tuesday, September 28, 2010 1:19 PM
  • Very Nice.  I hadn't run across that in 2010 yet.
    Paul Stork SharePoint Server MVP
    Tuesday, September 28, 2010 3:53 PM
  • that did the job.

    But I have a related problem. I want to add the eventreceiver to two lists, they are in the same sitecollection but on two different sites: 

    - List1 on http://myserver/site1

    - List2 on http://myserver/site2


    is it possible to add the eventreceiver to both lists?

    Wednesday, September 29, 2010 6:40 PM
  • If the list name is the same, make it a web scoped feature and activate it on both sites. The ListUrl attribute is relative to the web's root. If they're different I'd do it programatically in the feature receiver.
    Wednesday, September 29, 2010 7:08 PM