Wednesday, March 12, 2014

Programmatically Disable Event Receiver Firing on List Item in SharePoint 2010

Through this post, you will see how we will disable Event Firing for SP List Item for a Custom List.

Step:-1 Add a class file in your project. Let's name it clsEnableDisableEvent.cs

Step:-2 Put below code in above class file...

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace YourProjectNamespace
   public class clsEnableDisableEventSPItemEventReceiver
        public void DisableListItemEventFiring()
           this.EventFiringEnabled =false;

        public void EnableListItemEventFiring()
           this.EventFiringEnabled =true;

Step:-3 Now use above create class in your Web Part.

using (SPSite site = new SPSite("Your SharePoint Site Url"))
                using (SPWeb web = site.OpenWeb())
                    SPList list = web.Lists["YourCustomList"];
                    SPListItem item = list.GetItemById(1);
                    item["Title"] ="New Updated Title";

                    clsEnableDisableEvent objItemEvent = new clsEnableDisableEvent();



Run your code. Now when you update/Delete list item Event Receiver will not fire.  

No comments:

Post a Comment

SharePoint Deployment Error : The specified path, file name, or both are too long.

Hi, Sometimes we get surprised with below error while deploying wsp file... Solution : To overcome with this issue, we just ne...