Thursday, February 28, 2008

Adding Event Handlers for all Lists in SharePoint Using Features in WSS 3.0

To add event handler to all document libraries in the site:
Create a Class Library project "EventHandlerProject" in Microsoft Visual Studio 2005.
Add a class named "EventHandler".
Inherit this class from "SPItemEventReceiver".
Override the ItemDeleting method as follows:
public override void ItemDeleting(SPItemEventProperties properties)
properties.Cancel = true;
properties.ErrorMessage = "It should work now. its already too late";
Compile the above project and add the assembly in cache.
Create an elements.xml file and put the fillowing xml in it.
<elements xmlns="">
<receivers listtemplateid="101">
<assembly>EventHandlerProject, Version=, Culture=neutral, PublicKeyToken=a1901tr121134ect</assembly>

Create a feature.xml and put following XML in it.
<feature scope="site" id="FBC1E9AD-741E-492a-84FB-491B7FCA1D79" title="Event Handler Feature" xmlns="" description="My feature." hidden="false">
<elementmanifest location="Elements.xml" />

No comments:

Post a Comment

Feel free to give constructive feedback or let me know if it was helpful.