How to disabling event firing in SharePoint 2010
Today, I tested whether event receiver fires or not when I use SPListItem's Update methods.
The results are here.
Methods event firing
Update() fired
SystemUpdate() fired
The results are here.
Methods event firing
Update() fired
SystemUpdate() fired
SystemUpdate(false) fired
UpdateOverwriteVersion() fired
All methods fired !!
But I think people sometimes want not to fire a event receiver when a update method is used.
So, I would like to introduce how to disable event firing.
In SharePoint 2010, SPEventReceiverBase.DisableEventFiring
Method and SPEventReceiverBase.EnableEventFiring Method are already
obsolete. We need to use EventFiringEnabled Property.
A sample code is here.
- private void button1_Click(object sender, EventArgs e)
- {
- const string siteUrl = "http://sp2010";
- SPSite site = new SPSite(siteUrl);
- SPWeb web = site.RootWeb;
- SPList list = web.Lists["Announcements"];
- SPListItem item = list.Items[3];
- HandleEventFiring handleEventFiring = new HandleEventFiring();
- handleEventFiring.DisableHandleEventFiring();
- try
- {
- item.Update();
- }
- finally
- {
- handleEventFiring.EnableHandleEventFiring();
- }
- }
- public class HandleEventFiring : SPItemEventReceiver
- {
- public void DisableHandleEventFiring()
- {
- //obsolete
- //this.DisableEventFiring();
- this.EventFiringEnabled = false;
- }
- public void EnableHandleEventFiring()
- {
- //obsotete
- //this.EnableEventFiring();
- this.EventFiringEnabled = true;
- }
- }
http://stackoverflow.com/questions/5187119/sharepoint-workflow-is-still-recursive-on-item-change-even-with-sp2 Sharepoint Workflow is still recursive on item change even with sp2
http://www.mattjimison.com/blog/2011/05/11/disable-event-receivers-during-an-update/ Disable Event Receivers During an Update
http://flylib.com/books/en/4.221.1.37/1/ Inside Microsoft Windows Sharepoint Services Version 3 Event Receivers
http://sharepointgauravgoyal.blogspot.com/2012/08/make-read-only-or-hide-fields-in.html
http://weblogs.asp.net/bsimser/archive/2010/04/12/using-jquery-and-spservices-to-display-list-items.aspx