Monday 8 April 2013

How to Disable event firing on item edit

We often comes across many situations where we need to disable the event firing on item edit.

Here is a simple trick to do that.

First, create a class which inherits from SPItemEventReceiver class and IDisposable interface as shown below

class DisableEventFiring : SPItemEventReceiver, IDisposable
{
         bool bEvent;
         public DisableEventFiring()
        {
                   bEvent = this.EventFiringEnabled;
                   this.EventFiringEnabled = false;
         }
         public void Dispose()
        {
                  this.EventFiringEnabled = bEvent;
        }
}

Now just use this class for disabling the event firing like shown below: 

using(new DisableEventFiring())
{
           _item.update;
}

No comments:

Post a Comment