随笔 - 173  文章 - 1 评论 - 2374 trackbacks - 136

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 阅读(...) 评论(...) 编辑 收藏