Last active
December 26, 2015 09:59
-
-
Save matthanley/7133294 to your computer and use it in GitHub Desktop.
Exception-safe method of disabling event firing in SharePoint 2010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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