Event Receiver is an important feature of SharePoint. The use of Event Receiver is to handle the events. It is like a method that is triggered when an action occurs on a specified SharePoint object. Triggering actions have some activities including,
- Adding
- Updating
- Deleting
- Moving
- Checking In
- Checking Out.
We may need to perform some actions like notifying the person who created the list item, or deleted it. By using Event Receivers, we can easily maintain the secured data in SharePoint.
Example
There is a Document Library and the full permission has been given to your Manager. So, we need to configure that document library in a manner that if anyone is trying to add a document in a library, your manager will get an alert like "someone is trying to add documents in library. We need you approval. " Once your Manager approves, then only the user can add a document in library.
Once a user has added a document in a library, an auto-generated message will be sent to your manager. At this time, we require Event Receiver to do this thing.
Types of Event Receiver
There are two types of Event Receiver in SharePoint,
Example
There is a Document Library and the full permission has been given to your Manager. So, we need to configure that document library in a manner that if anyone is trying to add a document in a library, your manager will get an alert like "someone is trying to add documents in library. We need you approval. " Once your Manager approves, then only the user can add a document in library.
Once a user has added a document in a library, an auto-generated message will be sent to your manager. At this time, we require Event Receiver to do this thing.
Types of Event Receiver
There are two types of Event Receiver in SharePoint,
- Synchronous Event Receiver
- Asynchronous Event Receiver
Synchronous Event Receiver or Before Event Receiver
Before events fire before the corresponding event action occurs and before SharePoint has written any data to the content database.
Asynchronous Event Receiver or After Event Receiver
After events fire after the event action has completed and after SharePoint has written to the content database to commit the event action. After events do not support cancelling the event action. A common example is sending out email notifications to let all the members of a site know when a new document has been uploaded.
Classes of SharePoint Event Receiver
Before events fire before the corresponding event action occurs and before SharePoint has written any data to the content database.
Asynchronous Event Receiver or After Event Receiver
After events fire after the event action has completed and after SharePoint has written to the content database to commit the event action. After events do not support cancelling the event action. A common example is sending out email notifications to let all the members of a site know when a new document has been uploaded.
Classes of SharePoint Event Receiver
- Base class: Microsoft.SharePoint.SPEventReceiverBase.
- Base class for List Item: Microsoft.SharePoint.SPItemEventReceiver
- Base class for SharePoint List: Microsoft.SharePoint.SPListEventReceiver
- Base class for Email: Microsoft.SharePoint.SPEmailEventReceiver
We can use the event to perform the following activities
- Validate the Item
- Log the information
- Create associated items
Event Receiver Base Classes
- SPItemEventReceiver
- SPListEventReceiver
- SPEmailEventReceiver
- SPWebEventReceiver
- SPWorkflowEventReceiver
No comments:
Post a Comment