SharePoint Event Receiver Does Not Fire

1. Add Trace Log to see if it is really not firing:

string now = DateTime.Now.ToString(“ddMMyyyy-HHmmss”);
// Creates the text file that the trace listener will write to.
System.IO.FileStream myTraceLog = new System.IO.FileStream(“C:\\temp\\SharePoint Trace Log\\” + now + “.txt”, System.IO.FileMode.OpenOrCreate);
// Creates the new trace listener.
TextWriterTraceListener myListener =  new TextWriterTraceListener(myTraceLog);
Trace.Listeners.Add(myListener);
Trace.WriteLine(“Event Receiver Starting”);

myListener.Flush();
myTraceLog.Close();

2. Go to “Manage Site Features”, deactivate the feature and re-activate it again.


To completely uninstall Event Receivers and re-install it:

1. Retract and Remove the solution;

2. Check if there is any receiver attached to the list using the following PowerShell script:

Add-PsSnapin Microsoft.SharePoint.PowerShell -EA 0
$spWeb = Get-SPWeb -Identity http://yoursitesURL.com
$spList = $spWeb.Lists[“The List’s Name”]
$spList.EventReceivers | Select Name,Assembly,Type
$numberOfEventReceivers = $spList.EventReceivers.Count
Write-Host $numberOfEventReceivers

3. If there are receivers attached, use the following to delete the receivers:

Add-PsSnapin Microsoft.SharePoint.PowerShell -EA 0
$spWeb = Get-SPWeb -Identity http://yoursitesURL.com
$spList = $spWeb.Lists[“The List’s Name”]
$spList.EventReceivers | Select Name,Assembly,Type
$numberOfEventReceivers = $spList.EventReceivers.Count
if ($numberOfEventReceivers -gt 0) {
for( $index = $numberOfEventReceivers -1; $index -gt -1; $index–)
{
$receiver = $spList.EventReceivers[$index] ;
$receiver.Delete()
}
}

4. Install and Deploy the solution;
5. Check if there is any receiver attached to the list (Same as Step 2)
6. If not, go to ‘Manage Site Features’, deactivate and then activate the features.

 

Advertisements
This entry was posted in Event Receiver, SharePoint 2010, Visual Studio 2010 and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s