In WSS 2007, event handlers have been improved a lot, and it allows us to extend our SharePoint environment in a lot of ways. Events are fired not only in document libraries but also in lists - and even at various other levels (site and web level). It is also now possible to hook up multiple event handler assemblies to our list or library.
For ease of understanding, I'm using a tree structure. The user can traverse the tree and find the appropriate list for attaching the EH. :)
Using the code
The code is pretty simple and easy
CreateTree() is a recursive method which will fill the tree with all its child nodes including the lists under that particular site.
public void GetTreeView()
SPWebApplication wa =
SPSiteCollection wasites = wa.Sites;
rootnode = new System.Windows.Forms.TreeNode(wa.Name);
foreach (SPSite site in wasites)
SPWeb web = site.RootWeb;
TreeViewSerializer serializer = new TreeViewSerializer();
Application.StartupPath + "\\..\\..\\bhanu.xml");
How to use the utility
- Provide the URL of the web application.
- Click the "Explore" button.
- Navigate the tree view of the Site collection.
- Select the List node.
- Click the "Load Assembly" button and browse the assembly (Note: The assembly should be GACed first).
- Select the class name from the drop-down combo.
- Provide the sequence number.
- Select the event type from the drop-down combo.
- Click "Add Assembly".
- For removing the event handler, we need to select the relevant event handler node from the tree, if there is any event associated with it. Then, simply click the "Remove Handler" button.
If you are getting an Access Denied message after clicking the "Explore" button, then you are probably not running the RegisterEventHandler app in the context of a Site Collection Administrator account. Go to Central Administration -> Application Management -> Site Collection Administrators, and add yourself as the secondary site collection administrator. Be sure that you add yourself to the correct site collection.
Happy SharePointing.... :)