Creating Event receiver in SharePoint 2010
This is a Step-By-Step example of creating a simple Item added event receiver for a custom list in SharePoint 2010. The event receiver will change the Title of the item to current Date Time once its added to the list. We will create and deploy the solution as a sandbox and will run in debug mode.
Steps are :
1. Open Visual Studio 2010 and create a new Project.
2. In project types select Event Receiver and give it a name (Select .net framework 3.5).
3. Next, In the SharePoint Customization Wizard, choose Deploy as a sandboxed solution and specify the site url where you want the event handler to be deployed. See the Screen below.

Click Next.
4. Next, in 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 events and click next. See the screen below.

Click finish.
5. Next, We will write some quick code to Change the Title of an item to the current Data and Time when it is added to a custom list.
Code -
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPListItem _currentItem = properties.ListItem;
_currentItem["Title"] = DateTime.Now.ToString();
_currentItem.Update();
}
6. We are now all set to deploy our event receiver to the site we specified in Step 3. To build and deploy just press “F5″.
7. Once press F5 the solution gets deployed to your site and your Visual studio project goes into a debug mode. You can navigate to SPSite2010{site url}->Site Actions->Site Settings -> Under Galleries -> solution and verify that your solution is now deployed to the site. See the screen below.

8. Now we will quickly create a new custom List “My Custom List” and add a new item to test our handler.
Create List -

Create a New Item -
Once you add the Item just refresh the custom list page and you will see the results.
and your done.
Related Post : Event Receiver for Sites\webs in Sharepoint 2010






