SharePoint Event Receivers – A Detailed Overview
Handling some events is necessarily required while going to develop an application and event receivers are precisely the medium for doing the same. Consider for example, addition of a new item to an existing list.
In this case, you need to notify the person creating the list item and the same would be handled by an event receiver. Multiple events are handled easily by help of SharePoint event receiver classes.
In this blog, we will take an in-depth overview of these event receivers along with the method of creating a list event receiver in SharePoint 2013.
Event Receiver Types – Synchronous and Asynchronous…
Also referred as “Before” event receivers; Synchronous event receivers typically perform a custom action prior to happening of any event. If some conditions are met, it’s also possible to cancel the event.
On the other hand, Asynchronous receivers or simply “After” event receivers help to perform some action once the event has occurred. So, in this case, it’s not necessary that the action will be performed immediately after the event has happened.
Event Receiver Classes – 5 Main Types…
A quick view at the following table will clarify the five main types of event receiver classes along with the action that causes them.
|Class||Provides Event Handling Whenever|
|Microsoft.SharePoint.SPEmailEventReceiver||Any user sends an email to a specific list having e-mail feature enabled|
|Microsoft.SharePoint.SPFeatureReceiver||Any feature is acted upon|
|Microsoft.SharePoint.SPItemEventReceiver||Any action is done on a list item|
|Microsoft.SharePoint.SPListEventReceiver||Any modification done in list definition|
|Microsoft.SharePoint.SPWebEventReceiver||Any site/site collection gets moved/deleted|
Different Methods that need to be Over-ridden for Classes…
|Site Level Events||Site Deleted , Site Deleting, Web Deleted , Web Deleting, Web Moving|
|List Level Events||Field Added, Field Adding, Field Deleted, Field Deleting , Field Updated , Field Updating|
|Item Level Events||ItemAdded, ItemAdding, ItemAttachmentAdded, ItemAttachmentAdding, ItemCheckedIn|
|Feature Events||FeatureActivated, FeatureDeactivating, FeatureInstalled, FeatureUninstalling|
To know more about SharePoint Hosting, call : 1-855-909-3300
Steps to Creating Custom List Level Event Receiver…
1. Open Visual Studio 2010
2. Create empty SharePoint project
3. In SharePoint customization wizard, type SharePoint URL and check the box saying “Deploy as a sandboxed solution”. Click Finish.
4. Right click the project, then select following –
- Add new Item
- Create Event Receiver
5. Click Ok to open Event Receiver Settings Wizard. From the drop down, select “List Item Events” as the event receiver type and “Custom List” as the item type. Now check the box that says “An Item was Added” listed under Handle the following events. Click Finish to proceed.
6. Add following CODE in event receiver class of list –
public override void ItemAdded(SPItemEventProperties properties)
SPListItem _currentItem = properties.ListItem;
_currentItem[“Title”] = DateTime.Now.ToString();
7. Build & deploy the project to SharePoint
8. In order to verify that the solution has been deployed to the website, go to Site Actions > Site Settings > Galleries >Solution
9. Form a new Custom List with name “Test Event Receiver”. Next add a new item and Click Add
10. Enter “Test Item” as the title/name of new item. Refreshing the custom list will show results in the form of date & time
So, this was an overview of Event Receivers in SharePoint, hope this helps you understand Event Receivers and helps you use it with confidence.
- Julia is Techarex Network’s Content Marketing Associate for Intuit products. She has worked as a B2B and Marketing Strategist for the last seven years, helping businesses with software implementation for Customer Service, CRM, and Email Marketing. Julia thrives in helping companies find the right software solution for their projects. Aside from his obvious passion for Marketing, Julia admits to being a foodie and travel enthusiast.
- SharePoint Hosting2018.02.20How to select the best between Cloud-based SharePoint and On-Premise SharePoint?
- MS Office2018.02.19Top 7 Reasons for SMBs to Get Managed Microsoft Office 365 Services
- QuickBooks2017.12.04Understanding the Nitty-Gritty of Collaborative Accounting
- QuickBooks2017.11.30Key Considerations Before You Convert Your Existing Company File for QuickBooks 2018