Search code examples
sharepointmossevent-handling

Registering an event handler for a single list


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?


Solution

  • 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);