using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
 
namespace DisableEventFiring
{
   public classEventFiring : SPItemEventReceiver
    {
       public void DisableHandleEventFiring()
        {
           this.EventFiringEnabled =false;
        }
 
       public void EnableHandleEventFiring()
        {
           this.EventFiringEnabled =true;
        }
    }
}

//sample to use:
using (SPSite site = new SPSite("https://serverName/sites/Vijai/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists.TryGetList("Custom");
                    SPListItem item = list.GetItemById(34);
                    item["Title"] ="Updated Successfully";
                    EventFiring eventFiring = newEventFiring();
                    eventFiring.DisableHandleEventFiring();
                    item.Update();
                    eventFiring.EnableHandleEventFiring();
                    Console.WriteLine("Updated Successfully");
                    Console.ReadLine();
                }
            }

ref: http://www.c-sharpcorner.com/UploadFile/anavijai/programmatically-disable-event-firing-on-list-item-update-in/

posted on 2014-11-12 17:24  jianyi  阅读(753)  评论(0编辑  收藏  举报