Monday, September 21, 2009

Attaching an event handler to a list though code in SharePoint 2007

Scenario:
Attaching an event handler to a list in SharePoint 2007

Code:

SPWeb web = properties.Feature.Parent as SPWeb;
SPList list = web.Lists["[List Name]"];
String assemblyName = "[Assembly Name],Version=[Version],Culture=neutral,PublicKeyToken=[PublicKeyToken]";
String className = "EventReceiverClassName";
list.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assemblyName, className);
list.Update();

1 comment:

  1. Another option , you can use event handler class functions from SPCORE

    http://spcore.codeplex.com/

    :-)

    ReplyDelete