What is Event handler in SharePoint ? How to use it in a SharePoint site?

This article will tell you about event handler used in sharepoint. Event handler perform a action depending up on your code. It helps you to perform an action by you. Learn about Event handler in SharePoint? How to use Event handler in a SharePoint site? Here I am providing code and few steps for event handler.

Learn What is Event handler in SharePoint? How to use it in a SharePoint site?

I will create an event handler which will avoid deletion from a document library in your SharePoint site.

Follow these steps for Event handler:

Open Visual studio, File-New-Project

Choose C# as your language and Class library from the template section.

So before writing the code you need to add few references. Right click on your solution and select Add Reference... From .net tab select Windows SharePoint Services and Microsoft SharePoint.

Add this namespace in your class library:

using Microsoft.SharePoint;

namespace EventhandlerCode
public class eventhandlersample:SPItemEventReceiver
public override void ItemDeleting(SPItemEventProperties properties)

properties.Cancel = true;

properties.ErrorMessage = "Sorry! You can't delete items from this library";



Now build your application. It should succeed, if yes then fine. (Do not run your application now)
Open project menu from Visual studio, select your project name from the menu.

From new window select Signing tab, select the checkbox "sign the assembly" and from dropdownlist select new and provide a name. Leave it as it is for other options. Build your solution again.

Locate this path: C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\Your project name\your project name\bin\Debug

Drag .dll file of your project name in to C:\Windows\assembly

Go to this location.
Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/FEATURES

Create a folder EventHandler.
In this folder create 2 xml files.


<Feature Scope="Web" Title="Event Handler To avoid Delete" Id="1F579D91-4F4B-4389-B03B-7A92EF2EE210" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifest Location="Element.xml"/>


<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="101">
<Name>No Deletion</Name>
<Assembly>DeletingEventHandler1, Version=, Culture=neutral,


Open command prompt and prompt to
C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/BIN
Type below commands one by one

  • stsadm -o installfeature -filename EventHandler\Feature.xml

  • stsadm -o activatefeature -filename EventHandler\Feature.xml -url yoursiteurl

  • iisreset

Your task is completed now. Open your sharepoint site create a new document library, add few documents and try to delete any one of them. It will give you a warning message that you can delete.

Note: It will work for all document libraries of specified url.

Do not forget to give your valuable feedback.


Guest Author: Nitin Gupta08 Feb 2012

SharePoint Event Handlers Manager allows admins to browse, add, edit and remove SharePoint event handlers from any list or web. This SharePoint solution provides two features that enables admins to play with event handlers from within SharePoint interface.


Author: vysyaraju13 Feb 2012 Member Level: Bronze   Points : 0


Author: Phagu Mahato29 Oct 2013 Member Level: Gold   Points : 7

create a SharePoint Foundation event handler in Visual Studio, produce a replacement project of sort "class library" and so inherit from one among the event receiver base categories. once you choose the event receiver base category from that to inherit, make certain that your event receiver base is acceptable for the event you propose to capture and for the event host to that you propose to bind.
Sharepoint provides legion inbuild options for storing documents, managing information, making sub sites. you'll be able to produce your own lists, documents libraries, announancement, calendar. every list has its own events i.e Item Created, Item Updated Item Deleted etc. however if you would like to try and do some factor on any event, you wish to put in writing custom code for this. this may be done by exploitation Event handlers.

Event handler is occuring once some action happened in SharePoint web site. e.g. you're adding AN item to sharepoint list, you're deleting item from sharepoint list etc. primarily there square measure four sorts of categories obtainable for event handler.

• List things – SPItemEventReceiver
• List Columns – SPListEventReceiver
• web site – SPWebEventReceiver
• Email – SPEmailEventReceiver

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: