For disabling the events inside the extended class of SPItemEventReceiver then we will have a property named EventFiringEnabled. But if our class doesn’t extend SPItemEventReceiver then we can use the object of below class.
public class SPItemEventReceiverHandling : SPItemEventReceiver, IDisposable
{
public SPItemEventReceiverHandling(bool disableImmediately)
{
EventFiringEnabled = !disableImmediately;
}
public void Dispose()
{
EventFiringEnabled = true;
}
}
Example: item represents SPListItem
using (var eventReceiverManager = new SPItemEventReceiverHandling(true))
{
item.Update();
}
Note:
If the version of MOSS is 2007 then use EnableEventFiring and DisableEventFiring methods instead of EventFiringEnabled property.
No comments:
Post a Comment