Even handler is executed when some operation occurs in SharePoint site.
Suppose you want to add event handler when an item will be added, or item will be deleted from a document library.
So, i am going to create an event handler that will avoid deletion from a document library in Share Point.
Open Visual Studio 2008.
From Project type select C# and from template select Class Library.
i.e. simply you have to create a Class Library in Visual Studio.
Give name to your Class Library application.
Right click on project in solution explorer.
Then from .Net tab, add Microsoft SharePoint and Windows SharePoint Services
Now use this namespace.
So, your code will look like this.
public class myevent1:SPItemEventReceiver
public override void ItemDeleting(SPItemEventProperties properties)
properties.Cancel = true;
properties.ErrorMessage = “You can not delete items from here !!!”;
Now Open Project menu in Visual Studio. Select your project that will be last option in the menu.
From the new window select Signing, tick on the check box “sign the assembly” and from drop down list select new and give name. “No need to give any password”.
Now, Build your solution.
Open this location
C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2008ProjectsYour project nameyour project namebinDebug.
Here you will find a .dll file with same name as your application.
Now drag this .dll file in to C:Windowsassembly
(Note:Copy-paste will not work, just drag & drop)
Again locate this location
Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES
Create a folder myevent.
In that folder create 2 xml files. i.e. feature.xml and element.xml
Title=”Event Handler To avoid Delete”
(Note: id can be found from Visual studio, Tools->Create GUID, copy a id and paste it here)
<Name>Event Handler-Delete Avoid</Name>
<Assembly>DeletingEventHandler1, Version=184.108.40.206, Culture=neutral,
(Note:You may get public token from C:Windowsassemblyyour.dll file. Right click on your .dll file, select properties, now you will see the public token, copy that and paste.)
Now Open Command Prompt and do the below steps.
stsadm -o installfeature -filename yourfoldernamefeature.xml
stsadm -o activatefeature -filename yourfoldernamefeature.xml -url your site url.
Now create a document from Document Library and try to delete it.