Stop SharePoint events firing

To stop events firing in SharePoint 2007 we call a method to disable the event firing, perform our update and then call another method to enable it again. The code might look something like this.

this.DisableEventFiring();
item.UpdateOverwriteVersion();
this.EnableEventFiring();

This has changed in SharePoint 2010. We now have a protected property of type System.Boolean named EventFiringEnabled on the base class SPEventReceiverBase. Simply set this property to false to disable the event from firing before performing your update.

this.EventFiringEnabled = false;
item.UpdateOverwriteVersion();
this.EventFiringEnabled = true;

The methods used in SharePoint 2007 are still in the 2010 API but are marked as obsolete. Take note!

Reference

MSDN – SPEventReceiverBase.DisableEventFiring Method
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverbase.disableeventfiring.aspx

MSDN – SPEventReceiverBase.EnableEventFiring Method
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverbase.enableeventfiring.aspx

MSDN - SPEventReceiverBase.EventFiringEnabled Property
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.speventreceiverbase.eventfiringenabled.aspx

Adrian Henke’s Blog – Disable SharePoint item events firing during item updates
http://adrianhenke.wordpress.com/2010/01/29/disable-item-events-firing-during-item-update/

This entry was posted in SharePoint, SharePoint 2007, SharePoint 2010 and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>