DisabledItemEventsScope

Provides a code block in which an items events will NOT be fired. Useful for preventing Workflows from executing.
Language:
PowerShell
Keywords:
SharePoint
Code Snippet

Add-Type -ReferencedAssemblies "Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" -TypeDefinition @'
/***
REFERENCE: http://adrianhenke.wordpress.com/2010/01/29/disable-item-events-firing-during-item-update/
***/
public class DisabledItemEventsScope : Microsoft.SharePoint.SPItemEventReceiver, System.IDisposable
{
    bool oldValue;
    public DisabledItemEventsScope()
    {
        this.oldValue = base.EventFiringEnabled;
        base.EventFiringEnabled = false;
    }

    #region IDisposable Members
    public void Dispose()
    {
        base.EventFiringEnabled = oldValue;
    }
    #endregion
}
'@


Created 2011-10-13
comments powered by Disqus
Login