How to create a custom list level event receiver in SharePoint 2013 and SharePoint 2010

Gopal Muthukrishnan
 
SharePoint Developer
April 20, 2013
 
Rate this article
 
Views
63288

This article provides a detailed steps for creating a list event receiver in SharePoint. Although the steps explained are related to SharePoint 2010, its same for SharePoint 2013 too.

Follow the below steps to create an event receiver for a SharePoint List.

Step 1:

Open visual studio 2010 and create empty SharePoint project.

Step 2:

Enter the SharePoint URL in SharePoint customization wizard, Choose Deploy as a sandboxed solution and click Finish.

clip_image002

Step 3:

Right click the project and select Add new Item and select create event receiver and click ok. This would open up Event Receiver Settings Wizard

Step 4:

In the event receiver settings dialog select the “List Item Events” as a type of event receiver and “custom List” in the item source drop down. Select “An Item was Added” from Handle the following event and click finish.

clip_image004

Step 5:

In the event receiver class of list , add the below mentioned code. This is just a simple example to change the title to current date.

public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPListItem _currentItem = properties.ListItem;
_currentItem["Title"] = DateTime.Now.ToString();
_currentItem.Update();
}

Step 6:

Now build and deploy the project to the SharePoint

Step 7:

In SharePoint Site click Site Actions => Site Settings => Galleries =>Solution and verify that your solution is now deployed to the site.

clip_image006

clip_image008

Step 8:

Create  a new Custom List “Test Event Receiver” and Add a new item to test the project and click Add.

clip_image010

Step 9:

Create new item and enter “Test Item” in the Title text box

clip_image012

Step 10:

Once you add the item and refresh the custom list page , you can see the results as date and time as we have updated the data in event receiver.

clip_image014

Author Info

Gopal Muthukrishnan
 
SharePoint Developer
 
Rate this article
 
Works as SharePoint Developer in Chennai, India. ...read more
 

Leave a comment