How to create item event receivers in sharepoint ?

An event receiver created in Visual Studio using the SharePoint project template. Below are the step to create a simple Item added event receiver, which creates a new item in another list.

Step 1

Open Visual Studio 2016 and create an Empty SharePoint Project.

Step 2

Enter site URL and select Deploy as a farm solution and click Finish.

Step 3
Add a new item to the project. Right click project and select Add -> New Item  -> Event Receiver.

Step 4

Select event receiver and enter the title of the event receiver. Click the Add button.


Select An Item was Added under Handle the following events.

Step 7

Add below code in eventreceiver1.cs

public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPWeb aWeb = properties.Web;
SPList alist = aWeb.Lists[“et”];
SPListItem aItem = alist.Items.Add();
aItem[“Title”] = properties.ListItem[“Title”];
aItem[“Name”] = properties.ListItem[“name”];
aItem[“salary”] = properties.ListItem[“salray”];
aItem.Update();
}

In the above code I created list called “et”, I am adding data to this list using below code,

once user add data in to “event list” this event receiver copy the item in to “et” list.

the Item Added method is used instead of the Item Adding method.

Go to Elements.xml update receivers tag.

In the elements.xml you can see receivers tag listtemplateid replace that with ListUrl=”Lists\listname”

Right click on the solution click deploy.


Leave a Reply

Your email address will not be published. Required fields are marked *