Wednesday 29 October 2014

sharepoint event handler firing twice

While working on event receiver I found that my ItemAdding and ItemAdded receivers firing twice.

I gone through many articles and found  stackexchange link, saying that "You probably have your event receiver registered twice. Use PowerShell to find out." and  solution provided as follows:


$site = Get-SPSite http://myportal.com
$web = $site.OpenWeb("/path/to/my/site")
$list = $web.Lists["The List"]
$list.EventReceivers | Select Type, Class | Order Type, Class
I check with above PowerShell cmdLet but I found that only one event receiver registered with my list. :(

Then I done two modifications in my feature :

1- Set the scope of feature from Site to Web
















2- In Feature.template.xml set Scope="Web"








And its done. Now it is working fine.

Same issue happens when you try to set ListUrl instead of ListTemplate type in Event Receiver's Element.xml file.




















This issue is also fixed with the above solution.

Basically, ListUrl property does not work for Site Collection scope (Site Scope) but only with Web Scope (Site Level).

3 comments :

  1. Hello Sir i can't change my scope to Web because of some other requirement, so please what should i tell to get overcome of this problem.

    ReplyDelete
  2. Please tell what should I do to overcome this problem...
    I can't change feature scope to web scope, please tell any other solution.

    ReplyDelete
  3. Tabrez you can follow below link:
    https://ehikioya.com/add-event-receiver-to-specific-list-instance-in-sharepoint/

    ReplyDelete