I took it from this article
private void DeleteEventReceiverFromAList(string siteUrl)
{
using (SPSite site = new SPSite(siteUrl))
{
using(SPWeb web = site.OpenWeb())
{
try
{
SPList list = web.Lists["myList"];
if (list != null)
{
string className = "EventReceiverClass";
string asmName = "EventReceiverAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111111";
web.AllowUnsafeUpdates = true;
int receivers = list.EventReceivers.Count;
bool isAddedReceiverExist = false;
bool isUpdatedReceiverExist = false;
for (int i = 0; i < receivers; i++)
{
SPEventReceiverDefinition eventReceiver = list.EventReceivers[i];
if (eventReceiver.Class == className && eventReceiver.Type == SPEventReceiverType.ItemAdded)
{
eventReceiver.Delete();
break;
}
}
}
}
catch { }
finally
{
web.AllowUnsafeUpdates = false;
}
}
}
}
No comments:
Post a Comment