Search This Blog

Showing posts with label SharePoint 2013 Programmatically. Show all posts
Showing posts with label SharePoint 2013 Programmatically. Show all posts

Saturday, June 10, 2017

How to Disable Event Firing on List Item Update in SharePoint 2013 Programmatically

public classEventFiring : SPItemEventReceiver
{
  public void DisableHandleEventFiring()
  {
     this.EventFiringEnabled =false;
  }

  public void EnableHandleEventFiring()
  {
     this.EventFiringEnabled =true;
  }
}


class Program
{
  static void Main(string[] args)
  {
    using (SPSite site = new SPSite("https://serverName/sites/testsite/"))
    {
      using (SPWeb web = site.OpenWeb())
      {
        SPList list = web.Lists.TryGetList("Test List");
        SPListItem item = list.GetItemById(1);
        item["Title"] ="Updated Successfully";
        EventFiring eventFiring = newEventFiring();
        eventFiring.DisableHandleEventFiring();
        item.Update();
        eventFiring.EnableHandleEventFiring();
        Console.WriteLine("Updated Successfully");
        Console.ReadLine();
     }
   }
  }
}