Create Remote Event Receiver in SharePoint Online

In this tutorial, I will explain how to create a remote event receiver in SharePoint Online using Visual Studio. I will also show you how to deploy the event receiver to Microsoft Azure for SharePoint Online.

Note: The SharePoint Add-In model in SharePoint Online has been deprecated as of November 27th, 2023. Deprecation means that the feature will not get any new investments, but it’s still supported. The SharePoint add-in model will be fully retired on April 2, 2026, and will no longer be available after that date. The primary replacement technology for the SharePoint add-in model is SharePoint Framework (SPFx), which will continue to be supported in the future.

If you are planning to develop remote event receivers now, I will not recommend it; instead, use SPFx.

Remote Event Receiver in SharePoint Online

Remote Event Receivers (RERs) are components in SharePoint Online that handle events such as when items are added, updated, or deleted in SharePoint lists and libraries.

Remote Event Receivers rely on a SOAP communication channel that allows an external service to receive notifications when events occur in SharePoint. These events can be either synchronous or asynchronous, depending on the implementation needs.

Unlike traditional server-side event receivers used in on-premises SharePoint, RERs are external web services that run outside of SharePoint, making them suitable for the SharePoint Online environment.

Create a Remote Event Receiver in SharePoint Online

Follow the steps below to create a remote event receiver in SharePoint Online using Visual Studio.

  1. Open Visual Studio and then File -> New Project. Then in the New Project dialog box, choose Templates -> Visual C# -> Office/SharePoint and from there choose App for SharePoint like below. Provide a name and ensure that the .NET Framework version is set to 4.5.
create remote event receiver sharepoint online
  1. Then, choose a SharePoint developer site and select Provider-hosted, as shown below.
create a Remote Event Receiver in SharePoint Online
  1. Then it will ask to give credentials for the developer site, and then it will automatically select the SharePoint version, like below:
How to create a Remote Event Receiver in SharePoint Online
  1. Then in the web project type, select whether you want to create an ASP.NET Web Forms Application or “ASP.NET MVC Web Application“, like below. Here, we will choose ASP.NET Web Forms Application.
SharePoint Online Remote Event Receiver with Azure App Service
  1. Then choose “Use Windows Azure Access Control Service (for SharePoint cloud apps)” in the Configure authentication settings, as shown below:
implementing Remote Event Receivers in SharePoint Online
  1. Visual Studio will take some time and create two projects: one for the Add-in and another for the ASP.NET Web project, as shown below.
rer in sharepoint online
  1. Now select the Add-in project and from the properties, set True to “Handle App Installed” like below:
SharePoint Online list item added Remote Event Receiver example
  1. Once you make the property true, it will add an AppEventReceiver.svc file inside the Services folder, as shown below. In this class, we will handle the AppInstalled and AppUninstalling events.
Handle item updated event using Remote Event Receiver in SharePoint Online
  1. Then we will add our remote event receiver class. For this, right-click on the Add-in project (first project) and then Add -> New Item.
Debugging Remote Event Receivers in SharePoint Online
  1. Here, choose Remote Event Receiver in the Add New Item dialog box.
SharePoint Online Remote Event Receiver using Visual Studio
  1. Then choose List Item Events, event source as Custom List, and then event as “An Item was added”.
register Remote Event Receiver in SharePoint Online app
  1. Once you add the remote event receiver, the .svc (RemoteEventReceiver1.svc) file will be added into the App project as well as inside the Services folder inside the Web project, like below:
Remote Event Receiver limitations in SharePoint Online
  1. Here is my host web. I have added a SharePoint list with a Title and Description column. When a user adds an item to the list, they will enter the Title, and the Description will be populated from the remote event receiver. The list looks like this:
remote event receivers in sharepoint online

Now we need to generate the ClientId and ClientSecret. So navigate to the _layouts/15/appregnew.aspx page

Example: https://<tenantname>.sharepoint.com/sites/MyO365DevSite/_layouts/15/appregnew.aspx

They click on the Generate button for the Client ID and Client Secret fields. Then, give a title and Domain, and enter the website that we created in Azure (without https://). And the Redirect URI, put the website URL, make sure to give in https:

Here, the page looks like the following:

Remote Event Receiver permissions and authentication in SharePoint Online

Then open the web.config file and replace the ClientId and ClientSecret, which we have generated in the above page.

It looks like this:

create remote event receivers sharepoint online

Now open the AppManifest.xml file and give full control to the Site Collection like below:

sharepoint online remote event receiver example

Also, we need to add the ClientId in the AppManifest.xml file. Right-click on the AppManifest.xml file and select ‘View Code’. In the warning box, click “Yes” to open the code file.

create remote event receiver sharepoint online

There, add the ClientId in RemoteWebApplication inside the AppPrincipal tag. AppManifest.xml looks like this:

create remote event receiver sharepoint online step by step

AppEventReceiver Code:

In the AppEventReceiver file, we need to add the code to attach the event receiver to the host list. The code will be added to the ProcessEvent event. Here we are adding the AppInstalled and AppUninstalling event.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.EventReceivers;
using System.Reflection;

namespace DemoSharePointRERWeb.Services
{
public class AppEventReceiver : IRemoteEventService
{
/// <summary>
/// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled.
/// </summary>
/// <param name=”properties”>Holds information about the app event.</param>
/// <returns>Holds information returned from the app event.</returns>

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
SPRemoteEventResult result = new SPRemoteEventResult();
if (properties.EventType == SPRemoteEventType.AppInstalled)
{
using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false))
{
if (clientContext != null)
{
//Get reference to the host web list with name Feedback
var documentsList = clientContext.Web.Lists.GetByTitle(“DemoRemoteEventReceiverList”);
clientContext.Load(documentsList);
clientContext.ExecuteQuery();
string remoteUrl = “https://enjoysharepoint.azurewebsites.net/Services/RemoteEventReceiver1.svc”;
//Create the remote event receiver definition
EventReceiverDefinitionCreationInformation newEventReceiver = new EventReceiverDefinitionCreationInformation()
{
EventType = EventReceiverType.ItemAdded,
ReceiverAssembly = Assembly.GetExecutingAssembly().FullName,
ReceiverName = “RemoteEventReceiver1”,
ReceiverClass = “RemoteEventReceiver1”,
ReceiverUrl = remoteUrl,
SequenceNumber = 15001
};
//Add the remote event receiver to the host web list
documentsList.EventReceivers.Add(newEventReceiver);
clientContext.ExecuteQuery();
}
}
}
else if (properties.EventType == SPRemoteEventType.AppUninstalling)
{
using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false))
{
var list = clientContext.Web.Lists.GetByTitle(“DemoRemoteEventReceiverList”);
clientContext.Load(list);
clientContext.ExecuteQuery();
EventReceiverDefinitionCollection erdc = list.EventReceivers;
clientContext.Load(erdc);
clientContext.ExecuteQuery();
List<EventReceiverDefinition> toDelete = new List<EventReceiverDefinition>();
foreach (EventReceiverDefinition erd in erdc)
{
if (erd.ReceiverName == “RemoteEventReceiver1″)
{
toDelete.Add(erd);
}
}

//Delete the remote event receiver from the list, when the app gets uninstalled

foreach (EventReceiverDefinition item in toDelete)
{
item.DeleteObject();
clientContext.ExecuteQuery();
}
}
}
return result;
}

/// <summary>
/// This method is a required placeholder, but is not used by app events.
/// </summary>
/// <param name=”properties”>Unused.</param>

public void ProcessOneWayEvent(SPRemoteEventProperties properties)
{
throw new NotImplementedException();
}
}
}

RemoteEventReceiver1 code:

In the remote event receiver code, we will write the code that will handle the ItemAdded event.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.EventReceivers;
namespace DemoSharePointRERWeb.Services
{
public class RemoteEventReceiver1 : IRemoteEventService
{
/// <summary>
/// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
/// </summary>
/// <param name=”properties”>Holds information about the remote event.</param>
/// <returns>Holds information returned from the remote event.</returns>

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
SPRemoteEventResult result = new SPRemoteEventResult();
using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
{
if (clientContext != null)
{
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();
}
}
return result;
}

/// <summary>
/// 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.
/// </summary>
/// <param name=”properties”>Holds information about the remote event.</param>

public void ProcessOneWayEvent(SPRemoteEventProperties properties)
{

// On Item Added event, the list item creation executes

if (properties.EventType == SPRemoteEventType.ItemAdded)
{
using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
{
if (clientContext != null)
{
try
{
string title = properties.ItemEventProperties.AfterProperties[“Title”].ToString();
List lstDemoeventReceiver = clientContext.Web.Lists.GetByTitle(properties.ItemEventProperties.ListTitle);

ListItem itemDemoventReceiver = lstDemoeventReceiver.GetItemById(properties.ItemEventProperties.ListItemId);
itemDemoventReceiver[“Description”] = “Description from RER :: “+title;
itemDemoventReceiver.Update();
clientContext.ExecuteQuery();
}
catch (Exception ex) { }
}
}
}
}
}
}

Check out Windows Server Roles And Features Cannot Be Automatically Installed

Deploy Remote Event Receiver in SharePoint Online to Microsoft Azure

Now we need to deploy the remote event receiver.

Right-click on the web project and then click on Publish, like below:

Create a Remote event receiver using visual studio

In the Publish Web project, click on Microsoft Azure Web Apps as shown below:

deploy create remote event receiver sharepoint online

Here, log in to the Azure account, and it will display all the web apps. Choose the particular web apps like below:

deploy remote event receiver to Microsoft Azure sharepoint online

Then it will display the Publish Web screen with the Publish method, Server, Site name, Username, Password, and Destination URL. Do the “validate connection” and once it is successful. Then click on Next.

deploy remote event receiver to Microsoft Azure sharepoint online

Then click on the Next as shown in the fig below:

create and deploy remote event receiver sharepoint online

You can also click on the Start Preview button to see the preview.

create and deploy remote event receiver sharepoint online

Then right-click on the Add-in Project and click on Publish, like below:

create remote event receiver sharepoint online step by step

Then, in the Publish your app page, click on the Edit button like below:

deploy remote event receiver to Azure sharepoint online

Then, enter the ClientId and Client Secret that we created in the previous step. It looks like this:

deploy remote event receiver to Microsoft Azure sharepoint online

Now, click on the Deploy your web project again, like below:

sharepoint online remote event receiver deployment

Once the web project is deployed successfully, click on the Package the app as shown below:

create remote event receivers sharepoint online

Here, the website will be populated by default, and the clientId will also be populated by default, like below. Click the Finish button to generate the .app file.

remote event receiver sharepoint online step by step

Once the .app file is ready, we will deploy the .app file to the Apps in a Testing list on the developer site.

remote event receiver sharepoint

Once the app is installed successfully, open the list and add an item to it. We will only add the Title, and the description will be populated by the remote event receiver, as shown in the figure below:

sharepoint online remote event receiver example

I hope you got an idea of remote event receivers in SharePoint Online. I have explained how to create a remote event receiver in SharePoint Online using Visual Studio. I have also explained how to deploy the remote event receivers to Microsoft Azure.

You may also like:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…