views:

1370

answers:

5

I have a sharepoint event handler which I want to activate for a single list, not all the lists in the site. How do I go about this?

+2  A: 

Just that list or that list in each site ? I have been testing the code that run when the event happens and I have used a nice little tool from u2u, which allows me to add or remove event handlers per list.

This MSDN article is a nice primer.

Kasper
A: 

Got the answer....

We need to run this code, maybe in a console app... I still didn't get how to remove the event handler once it has been added, though...

string siteUrl = Console.ReadLine();

SPSite site = new SPSite(siteUrl);

SPWeb web = site.OpenWeb();

string listName = Console.ReadLine();

SPList list = web.Lists[listName];

string assemblyName = "Issue.EventHandler, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=89fde668234f6b1d";

string className = "Issue.EventHandler.IssueEventHandler";

list.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assemblyName, className);

ashwnacharya
A: 

Take a look at the code that comes with the tool from u2u that I posted earlier. It is a convenient tool when you are working with event handlers.

Kasper
It even allows you to remove eventhandlers :-)
Kasper
A: 

Another alternative is the "SharePoint Events Manager".

Events Manager is a Feature for SharePoint that allows administrators to manage events attached to their site's lists and document libraries directly using their browser.

This simple feature enables management of events on lists and document libraries through a new item on list settings menu.

You can view, add and delete events, and even find automatically interesting classes and events from an assembly name.

You can download this feature here, and install it using "stsadm -o addsolution -filename GatWeb.SharePoint.EventsManager.wsp".

This feature is localized in french and english.

+2  A: 

I recently gave a talk at our Sharepoint SIG about this very problem. The slides and tools are available here. You can

  • write a console app to do this
  • write a features that uses the code in your console app to deploy to the proper list
  • use PowerShell
  • use Brian Wilson's admin tool
jwmiller5