Sometimes we may be interested in disable events to perform some tests or processes but we're only able to execute DisableEventFiring() and EnableEventFiring() functions from a SPItemEventReceiver.
A possible solution is disable and enable event firing from any source code. To do that, you can follow the next steps:
- Add a new class in your namespace which inherits from SPItemEventReceiver.
- Create 2 functions in that new class to call EnableEventFiring() and DisableEventFiring().
namespace MyNamespace
{
public class MyEventFiring : SPItemEventReceiver
{
public MyEventFiring()
{
}
public void MyDisableEventFiring()
{
this.DisableEventFiring();
}
public void MyEnableEventFiring()
{
this.EnableEventFiring();
}
}
public class MyClass
{
//...
MyEventFiring mef = new MyEventFiring();
mef.MyDisableEventFiring();
item.Update(); //This Update can be executed withou event firings
mef.MyEnableEventFiring();
//...
}
}
No hay comentarios:
Publicar un comentario