Disable event firing on SharePoint list item update in SharePoint

This SharePoint tutorial, we will discuss how to disable event firing on SharePoint list item update in SharePoint 2010 or MOSS 2007.

Disable event firing on SharePoint list item update in SharePoint

If you are working in developing an event receiver using the SharePoint object model then you may need this code. Suppose through an event receiver you want to update something or you want to update a list item using server object model code then the item update event can go to an infinite loop.

When you will write code for this then we should write the code so that it will not go to the infinite loop. This is really helpful if you are working with an event like ItemUpdated, ItemUpdating, etc.

In 2007 two useful methods were there to write:

DisableEventFiring() and EnableEventFiring(). Here is how you can use:

try
{
this.DisableEventFiring();
//Then write your server object model code.
}
catch(Exception ex)
{
}
finally{
this.EnableEventFiring();
}

But these methods are obsolete in SharePoint 2010. Microsoft provided one properties name as EventFiringEnabled which we can use to enable or disable event firing.

try
{
this.EventFiringEnabled =false;
//Then write your server object model code.
}
catch(Exception ex)
{
}
finally{
this.EventFiringEnabled =true;
}

Or You can also make a class which will inherit from SPItemEventReceiver and use like below:

public class MyEventFiring : SPItemEventReceiver
{
public void DisableEventFiring()
{
this.EventFiringEnabled =false;
}
public void EnableEventFiring()
{
this.EventFiringEnabled =true;
}
}

And here you can use like below:

MyEventFiring myEventFiring = new MyEventFiring();
myEventFiring.DisableEventFiring();

//Your server side event handler code will go here.

myEventFiring.EnableEventFiring();

You may like following SharePoint event receiver tutorials:

This tutorial, we learned how to disable event firing on SharePoint list item update in SharePoint 2010 or MOSS 2007.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>