Create and deploy Event Receiver Feature and Solution package

Here is a Step-by-Step description of how to create an Item event receiver as a feature and then creating a solution package for it. I this code we will be creating an event receiver for document library types templates where we will assign a value to a custom field called "Location" on adding of a document.

Remember - document added is ItemAdded and if we need to assign any value to document properties ( like Title, File Type etc.) we need to use ItemUpdating.

So lets start.

1. Create a new Webapplication project and name it as "myEventReceiver".

2. Add Refernces to Microsoft.Sahrepoint.dll in the Project.

3. Create the below two folders in your project

a. ItemEventreceiver

b. Package

4. Add the below three files in the ItemEventreceiver folder (created in step 3)

a. Add a xml file and name it as elements.xml
b. Add a xml file and name it as feature.xml
c. Add a class file and name it as EventReceive.cs

5. Now add another xml file in the project (not in the ItemEventreceiver folder) and name it as manifest.xml.

6. Lastly, add the below two text type files in your project

a. mysolution.ddf
b. mypackage.bat

7. Sign the Project. Generate a key pair using sn.exe tool and save it to your local machine. Now go to Project Properties and in signing tab browse for this key.
Build the Project and get the full name of the dll or assembly from the reflector.

Now lets add some code in these files

EventReceive.cs -

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.SharePoint;

namespace EventReceivernamespace
public class EventReceiver : SPItemEventReceiver

public override void ItemUpdated(SPItemEventProperties properties)

SPItem oItem = properties.ListItem;

oItem["Location"] = "New Jersey";






<?xml version="1.0" encoding="utf-8" ?>
<Elements Id="sfb3c25c-f311-4dd3-86de-29904210c7d5" xmlns="">
<Receivers ListTemplateId="101">
<Assembly>myEventReceiver, Version=, Culture=neutral, PublicKeyToken=9275960caf741af9</Assembly>

Use the fully qualified name of the assembly for this project in your assembly tag.


<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="2e4d1d48-589e-4328-8a24-a554b2cdcbad"
<ElementManifest Location="elements.xml" />


<?xml version="1.0" encoding="utf-8" ?>
<Solution SolutionId="d7f69035-e74c-44f2-aaa8-928418f6ead0" xmlns="">
<FeatureManifest Location="ItemEventreceiver\feature.xml" />
<Assembly Location="myEventReceiver.dll" DeploymentTarget="GlobalAssemblyCache">
<SafeControl Assembly ="myEventReceiver, Version=, Culture=neutral, PublicKeyToken=9275960caf741af9"
Namespace ="EventReceivernamespace" TypeName ="*" />
</Assembly >

mysolution.ddf -

.OPTION EXPLICIT ; Generate errors
.Set CabinetNameTemplate=mycustomEventReceiver.wsp -> .wsp name
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
.Set CompressionType=MSZIP ;** All files are compressed in cabinet files
.Set UniqueFiles="OFF"
.Set Cabinet=on
.Set DiskDirectory1=Package

;adds manifest file

;adds webpart dll

;sets the title webpart feature directory
.Set DestinationDir=ItemEventreceiver

;adds the feature manifest to the feature directory

;adds the element manifest to the feature directory

mypackage.bat - This file will create the soltuion package for you and will place it in the Package folder ( that you created in step 3) on build of your project. In addition to that this will also drop the .wsp file in 12 hive's BIN folder (Make sure you have Permissions to drop the .wsp in BIn directory).

@SET MakeCabTool=makecab.exe
@SET WSP=mycustomEventReceiver
@SET DESTDIR="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN"
@SET SPAdminTool=%CommonProgramFiles%\Microsoft Shared\web server extensions\12\BIN\stsadm.exe

if EXIST Package\%WSP%.wsp del Package\%WSP%.wsp
"%MakeCabTool%" /f mysolution.ddf /D CabinetNameTemplate=Package\%WSP%.wsp

if EXIST Package\ del Package\
"%MakeCabTool%" /f mysolution.ddf /D CabinetNameTemplate=Package\

XCOPY /r /y Package\*.wsp %DESTDIR%

Lastly, Edit the Project Properties and under Build Events in "Post Build event command line" box write the below

CD $(ProjectDir)

Now build the Project. You should see the mycustomEventReceiver.wsp in your package folder and in SharePoint's BIN directory as well

Now add your solution in sharepoint solution store via stsadm and deploy it.

To do this,

Open the stsadm.exe (from 12 hive bin) and type the below command

stsadm -o addsolution -filename mycustomEventReceiver.wsp

Now got to Cental admin -> Operations-> solution management and click on mycustomEventReceiver.wsp. Click on Deploy and choose one of the web applications that you want to deploy the feature on.

Lastly, Browse to that web application -< Site Settings -< Site features and activate the feature.

To Test -

1. Create a custom document library and create a column "Location" in it.
2. Now upload the document.
3. Once your done uploading and adding properties like Title and stuff for the document you will see the Location column populated with the value "New Jersey"



  1. For SP2010:

  2. Great post! I am see the programming coding and step by step execute the outputs.I am gather this coding more information. It's helpful for me my friend. Also great blog here with all of the valuable information you have.
    Sharepoint Training in Chennai



This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at .

Copyright (c) 2010 @ All rights are reserved.Do Not Copy.

@ Learning