Tuesday, August 5, 2008

Deleting all the registered event handlers from a list

Scenario:
You want to deleting all the registered event handler from a particular list/library

Code:

using Microsoft.SharePoint ;

SPSite site = new SPSite("http://mossserver");
SPWeb web = site.AllWebs["/"];
SPList list = web.Lists["List_Name"];

int itemCount = list.EventReceivers.Count;

for (int k = itemCount-1 ; k >= 0 ; k--)
{
list.EventReceivers[k].Delete();
}
Use:
Console Application, At the time of Feature De-activation

0 comments: