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...
Step:-3 Now use above create class in your Web Part.
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 clsEnableDisableEvent: SPItemEventReceiver
{
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();
objItemEvent.DisableListItemEventFiring();
item.Update();
objItemEvent.EnableListItemEventFiring();
}
}
Run your code. Now when you update/Delete list item Event Receiver will not fire.
No comments:
Post a Comment