Skip to content

Instantly share code, notes, and snippets.

@matthanley
Last active December 26, 2015 09:59
Show Gist options
  • Save matthanley/7133294 to your computer and use it in GitHub Desktop.
Save matthanley/7133294 to your computer and use it in GitHub Desktop.
Exception-safe method of disabling event firing in SharePoint 2010
public class SPDisableEventFiring : SPEventReceiverBase, IDisposable
{
private bool _eventFiringEnabled;
public SPDisableEventFiring()
{
_eventFiringEnabled = base.EventFiringEnabled;
base.EventFiringEnabled = false;
}
public void Dispose()
{
base.EventFiringEnabled = _eventFiringEnabled;
}
}
/** Usage */
using (SPDisableEventFiring scope = new SPDisableEventFiring())
{
// Do stuff without firing events
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment