Hi ,
I am able to fire an Event using an Event receiver which I created using Visual Studio 2010 . But instead of firing once, it fires twice. I tried to debug the code and I saw that the was getting executed twice. Is there any particular reason that this is executing in such a manner?


Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 13, 2015, 12:50 AM EDT
Hi Supreeth,
What is the type of the ER you are running . Is is it on an item or some other SP object ? Is it an Asynchronous one or a Synchronous one ?Please specify the event you are trying to catch
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 13, 2015, 1:13 AM EDT
Supreeth,
I will give you couple of inputs anyway :
1. If your ER is trying to catch the document upload event and the library has Requires Check out option enabled then the ER will fire twice . This is the default behavior in SP .
Workaround
•Click on a list in the left navigation menu (or otherwise get into a list)
•Click the Library tab in the Ribbon
•Click Library Settings button in the Library Tab
•This will take you to the list information screen
•Click the Versioning settings link
•The Require Check Out radio button should appear in the list of settings
2.Disable Event Firing in code .
this.EventFiringEnabled = false;
item.Update();
this.EventFiringEnabled = true;
3.Sometimes ER are registered twice .Use the Powershell to find that out :
Run the below powershell script to see if the event receivers are attached or not. If they are attached multiple times, just delete them using a powershell.
Check Event receivers using powershell:-
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$spWeb = Get-SPWeb -Identity "sitename"
$spList = $spWeb.Lists["yourlistname"]
$spList.EventReceivers | Select assembly,name
Replace "sitename" with your site url and "yourlistname" with list name.
Once you confirm the event receivers, use below to delete them
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$spWeb = Get-SPWeb -Identity "your site url"
$spList = $spWeb.Lists["TrackTravel"]
$evts = $spList.EventReceivers | where {$_.Assembly -eq ""your assembly"}
$evts
if ($evts.Count -gt 0) {
foreach ($evt in $evts) {
Write-Host("Deleting..." + $spList.RootFolder.ServerRelativeUrl + ", " + $evt.Type)
$evt.Delete()
}
}
Once you run this, you can now redeploy your solution.
Thanks,
If you found this useful Please mark this as Answer
Supreeth JRank #2,205 · 639 reputationPosted Oct 13, 2015, 1:55 AM EDT
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 13, 2015, 2:32 AM EDT
Supreeth JRank #2,205 · 639 reputationPosted Oct 13, 2015, 3:17 AM EDT
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 13, 2015, 10:17 PM EDT
Supreeth JRank #2,205 · 639 reputationPosted Oct 14, 2015, 12:15 AM EDT
Rupali ShindeRank #539 · 4.5K reputationPosted Oct 14, 2015, 4:16 AM EDT
Supreeth JRank #2,205 · 639 reputationPosted Oct 14, 2015, 10:17 PM EDT
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 14, 2015, 10:35 PM EDT
Supreeth JRank #2,205 · 639 reputationPosted Oct 14, 2015, 11:01 PM EDT
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 14, 2015, 11:08 PM EDT
Supreeth JRank #2,205 · 639 reputationPosted Oct 15, 2015, 12:31 AM EDT
Rupali ShindeRank #539 · 4.5K reputationPosted Oct 15, 2015, 12:39 AM EDT
Supreeth JRank #2,205 · 639 reputationPosted Oct 15, 2015, 1:31 AM EDT
Supreeth JRank #2,205 · 639 reputationPosted Oct 20, 2015, 10:13 PM EDT
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 21, 2015, 12:16 AM EDT
Great work Supreeth . It could have been that the old feature was attached twice to the list .
Thanks,