SharePoint暂时禁用事件触发

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/

你可能感兴趣的:(SharePoint)