Remote event receivers in SharePoint

sharePoint


Remote event receivers in SharePoint

To handle events in a cloud in SharePoint, you need to create remote event receivers. Remote event receivers handles events that occur to an item inside the app for e.g.  list, list item, web.App event receivers handle events that occur in the app itself, such as when it's uninstalled ,installed,  and upgraded etc.

Remote event receiversin SharePoint


If you create a remote event receiver, your cloud app can respond when a user made changes like  adds, update, or deletes a list, a list item, or a web etc . For example, you can prevent users from deleting a item from a list, and you can track which users adds lists In  your app etc , or we can perform many more such type of operations.

To add a remote event receiver in share point, choose the Remote Event Receiver project template, then specify the type of remote event receiver that you want to add such as  you can create a List Item Events receiver, which fires when a user adds ,updates or deletes a list item in a list. You can view the list of available remote events when you creating it, or you can view them by opening Solution Explorer. When you are creating a remote event receiver, also you must specify the source of the events that you want that receiver to handle. For a List Item Events receiver, you can specify any list (such as ContactsCalendar Custom List etc) in the current solution or on the site at the Site Url property of the app for SharePoint project.

When you add a remote event receiver on a cloud , following actions  are occurs:

  • To process remote events, your solution needs a web application, so one is added if one doesn't already exist. That application is then used as the host web application for the app for SharePoint.

  • A web service, such as RemoteEventReceiver1.svc, is added to the web application to handle the events that you specified when you added the remote event receiver to the app for SharePoint. The web service contains a code file to handle the remote events.


After you create the remote event receiver, you add code to the code file for the web application service to handle the events.

By default, the code file contains two methods:  ProcessOneWayEvent() and ProcessEvent() .

ProcessEvent() handles events that occur before an action occurs, such as when a user adds or deletes a list item. ProcessOneWayEvent() handles events that occur after an action occurs, such as after a user adds an item to a list or deletes an item from a list.

  • A project item for the remote event receiver is added to the app for SharePoint project. The Elements.xml file for the remote event receiver references the web service in the web application and the remote events that you specified. The following example shows an Elements.xml file that handles the addition or deletion of a list item:


[xml]
<pre><?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="<a href="http://schemas.microsoft.com/sharepoint/">http://schemas.microsoft.com/sharepoint/</a>">
<Receivers ListTemplateId="104">
<Receiver>
<Name>RemoteEventReceiverItemAdding</Name>
<Type>ItemAdding</Type>
<SequenceNumber>10000</SequenceNumber>
<Url>~remoteAppUrl/RemoteEventReceiver.svc</Url>
</Receiver>
<Receiver>
<Name>RemoteEventReceiverItemDeleting</Name>
<Type>ItemDeleting</Type>
<SequenceNumber>10000</SequenceNumber>
<Url>~remoteAppUrl/RemoteEventReceiver.svc</Url>
</Receiver>
</Receivers>
</Elements>
[/xml]

To change the events that the remote event receiver handles, open Solution Explorer, open the Properties window for the remote event receiver, expand the SharePoint Events node, and then set only the events that you want to handle to True.

 
Share on Google Plus

About JK STACK

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment