In this article we can see how to create a new Event Receiver for SharePoint 2013 with Visual Studio 2012.
Follow the bellow steps to create a new Event Receiver
1. Create a new Empty SharePoint 2013 Project.
3. Right click the project and select Add new Item and select create event receiver and click ok.
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.
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();
}6. Now build and deploy the project to the SharePoint
7. In SharePoint Site click Site Actions => Site Settings => Galleries =>Solution and verify that your solution is now deployed to the site.
8. Add new Item list the title will update with current date.
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPListItem _currentItem = properties.ListItem;
_currentItem["Title"] = DateTime.Now.ToString();
_currentItem.Update();
}6. Now build and deploy the project to the SharePoint
7. In SharePoint Site click Site Actions => Site Settings => Galleries =>Solution and verify that your solution is now deployed to the site.
8. Add new Item list the title will update with current date.
0 comments:
Post a Comment