In WSS 2007, event handlers have been improved a lot and will allow you to extend your SharePoint environment in a lot of ways. We have synchronous before (means you can now cancel a user action) and asynchronous after events. Events are fired not only in document libraries but now also for lists - and even at various other levels (site and web level). It is also now possible to hook up multiple event handler assemblies to your list or library you work with. During my session at the SharePoint Advisor Summit in Vegas I demonstrated a small Windows application I am using to register an event handler for a list. And I also promised to make it available for download. Here is the link to it. Remember that this is demoware and meant to be something to learn from (that's why you get the full source code) and it was created for beta 1. So if you are not into the beta program, wait a couple of weeks and then you will be able to download beta 2 and I will make sure that I have by that time tested and recompiled it for that version.
Here are kind of the demo steps I used:
- Use VS.NET 2005 to create your event handler. It can be as simple as this:
using Microsoft.SharePoint;
public class MyEventHandler: SPItemEventReceiver
{
public override void ItemDeleting(SPItemEventProperties properties)
{
properties.Cancel = true;
properties.ErrorMessage = "Sorry, we do not allow deleting of items...";
}
}
- Next, sign your assembly and deploy it into the GAC.
- Open the EventHandler Explorer tool
- Type in the URL to your SharePoint site
- Select the list/library/content type/web you want to hook up with.
- Load the assembly.
- Select the class, enter the sequence number and the type of event
- Click register.
- Double-click the node in the treeview to verify your work.