Register an event handler for a single list

I have a sharepoint event handler that I want to activate for a single list, and not for all lists on the site. How should I do it?

+3
source share
6 answers

Got a response. We need to run this code, perhaps in a console application. I still have not figured out how to remove the event handler when it was 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);
+3
source

Only this list or list on each site? I tested the code that fires when an event occurs, and I used a beautiful little tool from u2u that allows me to add or remove event handlers in the list.

MSDN .

+2

SharePoint Events Manager.

- SharePoint, , , .

.

, .

"stsadm -o addsolution -filename GatWeb.SharePoint.EventsManager.wsp".

.

+2

Sharepoint SIG . .

  • write a console application to do this
  • write the functions that use the code in your console application to expand it into the appropriate list
  • use powerhell
  • use the Brian Wilson administration tool
+2
source

You can use this code to remove event handlers:

for (int i = 0; i < olist.EventReceivers.Count; i++) {
    olist.EventReceivers[i].Delete();
}
+1
source

Take a look at the code that comes with the u2u tool I posted earlier. This is a handy tool when you work with event handlers.

0
source

Source: https://habr.com/ru/post/1699647/


All Articles