Click here to Skip to main content
Click here to Skip to main content
Go to top

ManageEventHandler

, 27 Feb 2008
Rate this:
Please Sign up or sign in to vote.
A Windows application to register an event handler for a desired list only.

Introduction

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. Smile | :)

Using the code

The code is pretty simple and easy to understand. 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 = 
      SPWebApplication.Lookup(new Uri(textBoxSiteCollectionURL.Text));
    SPSiteCollection wasites = wa.Sites;

    //SPWebCollection sub_SubWeb;
    System.Windows.Forms.TreeNode rootnode;
    //System.Windows.Forms.TreeNode firstchild;
    rootnode = new System.Windows.Forms.TreeNode(wa.Name);
    treeView1.Nodes.Add(rootnode);

    foreach (SPSite site in wasites)
    {
        SPWeb web = site.RootWeb;
        CreateTree(web, rootnode);
        GetList(web, rootnode);
    }
    //For writing treeview in xml file.....
    TreeViewSerializer serializer = new TreeViewSerializer();
    serializer.SerializeTreeView(this.treeView1, 
      Application.StartupPath + "\\..\\..\\bhanu.xml");
}

How to use the utility

  1. Provide the URL of the web application.
  2. Click the "Explore" button.
  3. Navigate the tree view of the Site collection.
  4. Select the List node.
  5. Click the "Load Assembly" button and browse the assembly (Note: The assembly should be GACed first).
  6. Select the class name from the drop-down combo.
  7. Provide the sequence number.
  8. Select the event type from the drop-down combo.
  9. Click "Add Assembly".
  10. 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.

Caution!!!

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.... Smile | :)

Cheers!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bh@nu
Team Leader
India India
"In the attitude of silence the soul finds the path in an clearer light, and what is elusive and deceptive resolves itself into crystal clearness. My life is a long and arduous quest after knowledge & Truth."
I'm playing with all ancient and new Microsoft Technologies since last two and half years.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 28 Feb 2008
Article Copyright 2008 by Bh@nu
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid