Create a blank visual studio solution, it does not matter which project type you use (i would recommend a class library project). In your new project, add a new folder called ‘DeletingEventHandlerFeature’.
Within this new folder, create two XML files – one called Feature.xml and the other called Elements.xml.
Your solution explorer window in Visual Studio should look like this:
The feature.xml is the xml file which defines the feature itself, open the feature file and add the following code:
Title=”Deleting Event Handler”
Id=”ENTER A GUID HERE”
Be sure to enter a unique GUID into the ‘id’ attribute by generating one from within Visual Studio. The elements.xml file will call the dll we created earlier and will specify the type of list that the event handler will attach to. In order to tell the feature the details of the dll it is using, we need to get the assembly and class name of the dll we created in part 1, I would recommend a program called the .NET Reflector to do this – http://www.aisto.com/roeder/dotnet/.
Enter the following code into the elements.xml file, replacing the <assembly> and <class> with the details of your dll:
<Assembly>DeletingEventHandler, Version=220.127.116.11, Culture=neutral, PublicKeyToken=81323876ac0307e0</Assembly>
In order to specify the correct list type to attach to, change the Receivers ListTemplateId accordingly, to see a full list of SharePoint list types, visit the following url: http://msdn.microsoft.com/en-us/library/ms431081.aspx.
Now we have created our feature, we must deploy the dll to the GAC (Global Assembly Cache) and install/activate our feature. Log on to your SharePoint web front end server and copy the dll created in Part 1 to ‘C:WindowsAssembly’, this will install the dll into the GAC.
Copy the folder created in your visual studio project to the following folder on your SharePoint server: ‘C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12TEMPLATEFEATURES’, you can use an XCOPY command at the project debug time if you wish.
To install the feature, you will need to use the SharePoint ‘STSADM’ admin tool, run this from the command line with the following switches:
-o installfeature -name DeletingEventHandlerFeature
-o activatefeature -name DeletingEventHandlerFeature -url ‘Site URL Here’
Once you have run these commands, be sure to do an IISRESET, the event handler should now be attached to lists of the type which you specified in the elements file, it will also be attached for all future lists of that type that are created.