Tuesday, April 2, 2013

Sharepoint 2013- Handling Event receivers

In SharePoint 2013, to handle events in share point app need to create Remote event receivers or App Event receivers. Yes, In SharePoint 2013 event receivers are modified little bit and two new concepts are introduced.

Remote Event Receivers:

Remote event receivers handles events in an item in the app such as list item, library item or web. In remote event receivers, app responds, when ever item added, updated or deleted in a list/library. When ever creating new remote event receiver you can select the type of event receiver. for Eg. you select ListItemEvent, that fires whenever user add/updates/deletes the list item.
  • Remote event handler, a web application should be exists.
  • Web service will be added to the web application  That web service contains the code to handles the event.

Code file contains two methods ProcessEvent() and ProcessOneWayEvent().


ProcessEvent() handles before action happened  means before item added/updated.deleted. This is 2 way Synchronous event. Here 2- way means, remote calls will handled and provides code to the share point to get context token for call backing to share point.
ProcessOneWayEvent() handles after action happened  means after item added/updated/deleted. This is one way Asynchronous event. One way means will just call the web service without callback to share point.

How Remote Events Works?
  • User makes an action (Add new/ Update/delete)
  • Share point communicates to the ACS and asks the Access token for the current Logged-in user information
  • Share point communicated to the web service and what to do for the event in the back end system.
  • Web service will Communicates to the ACS for it's token to do operation in SharePoint back end. Back end System sends Success/Failure message to web service.
Click here to check all the events support remote handler.

following XML shows the elements.xml file that shows remote event receiver item adding. Here URL means the URL of web service contains code to handle the event. 


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListTemplateId="104">
      <Receiver>
        <Name>MyCustomRemoteEventReceiverItemAdding</Name>
        <Type>ItemAdding</Type>
        <SequenceNumber>10000</SequenceNumber>
        <Url>~remoteAppUrl/RemoteEventReceiver1.svc</Url>
      </Receiver>
  </Receivers>
</Elements>

App Event Receivers:

App event receivers can handles the events for an app in share point like App installing, App uninstalling, App deleting.This will be useful thing, you want to send an notification email to the users when an app got deleted. We can handle few app events through this model. we can't update a list item in HandleAppInstalled Event, because there is no list exists in the app web when first installed the app.  

We can handle following events,
  • Handle App Installed
  • Handle App Uninstalling
  • Handle App Upgraded
To handle the event we need to set the property value to True and False to disable the handler. A web service will be added to the web application, that contains the code file to run the handler. We have ProcessEvent(), ProcessOneWayEvent() methods that contains code. InstalledEventEndPoint tag contains web service code file url, in the AppManifest.xml file. To disable the handler we need to make the property value to False for the event in the properties window. 

Will update two more posts regarding how to create remote event handlers and App event handlers.

Share this

0 Comment to "Sharepoint 2013- Handling Event receivers"

Post a Comment