Thursday, 23 May 2013

Disable all event receivers in SharePoint 2010

I found the following page( here ) about disabling global event receivers. A fantastic post that solves a very specific need.

The crux of the solution is as follows:

public class MyClass
{
  SPListItem i = SPContext.Current.Web.Lists["Blah"].Items[0]
  HandleEventFiring handleEventFiring = new HandleEventFiring();
  handleEventFiring.DisableHandleEventFiring();

  try
  {
     i.Update();
  }
  finally
 {
    handleEventFiring.EnableHandleEventFiring();
  }
}

public class HandleEventFiring : SPItemEventReceiver
{
       public void DisableHandleEventFiring()
      {
          this.EventFiringEnabled = false;
       }

       public void EnableHandleEventFiring()
      {
          this.EventFiringEnabled = true;
       }

No comments:

Post a comment