SharePoint fires different events when you create custom event receivers. The events triggered by SharePoint are List Item events, List Email events, List Workflow events and Feature events. These can further classified into synchronous and asynchronous events. Synchronous events are executed on the same thread as the code, before sending response to the browser. Asynchronous events are those that take place after the action has happened.
Event handlers in SharePoint used for validating an item before it is adding it to the list. Sending a custom e-mail when an item is added to a list. Logging to external database for audit purpose. You can package the event receivers as a solution file to deploy to the SharePoint event host.Visual Studio 2010 supports project template for creating event receivers.This post explains how to create a custom event handler for the ItemAdding event.
1. Create a list in SharePoint user interface with name Contacts of template contacts.
2. Launch Visual Studio 2010 and create a new project and select EventReceiver project template from the dialogue box
3. Visual Studio by default selects the SharePoint site available on the machine. Select Deploy as a Farm Solution and click on Next to proceed to next step
4. Select List Item Events from the drop-down that you want to add and select event source as shown below
5. Add the code to the event receiver to validate the items before it is getting added to the list
6. Build and execute the solution that brings the default browser with contact list
7. If you look at the element.xml file then you will notice properties such as Name, Type and ListTemplateId
SharePoint determines the order of execution of the event handlers by using Sequence Number element.
8. Visual Studio adds another project item called Features. If you have custom code that makes the changes to site templates and creates various lists then you can deploy this code across all web front ends in SharePoint farm.
9. When you build and run your Visual Studio solution it automatically creates a package and deployed to test site and activate it.
10. Event receivers you create in Visual Studio inherits from particular SharePoint event receiver class. All event receivers except Feature event receivers are inherited from base class called SPEventReceiverBase
|Share this post :|