Forum Discussion
rjspdev
Aug 24, 2023Copper Contributor
SharePoint On-Premises Event Receiver migration to SharePoint Online
Hello, There is a requirement to migrate SharePoint On-Premises sites to SharePoint Online (SPO). Some of the customization in the current 2013 on-prem site include Event Receivers specially ItemDele...
MSchmittnaegel
Aug 29, 2023Brass Contributor
We start using Remote Event Receivers + Azure Functions a few years ago to check and block ItemDeleting events. It was tricky to get the response right, but it works quite well.
In a nutshell, it is:
1. Provide something which can handle HTTP POST from SPO (e.g. an Azure Function)
2. Use Add-PnPEventReceiver and point to the URL of (1)
Depending on what your Event Receiver should do, it might be necessary to access SP from your code -> CSOM or Graph API. When using *ing events, it is important to return the correct response. Here's a snippet to give you an idea of the response:
string responseString =
$"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body>" +
$"<ProcessEventResponse xmlns=\"http://schemas.microsoft.com/sharepoint/remoteapp/\">" +
$"<ProcessEventResult xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +
$"<ChangedItemProperties xmlns:a=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">" +
$"</ChangedItemProperties>" +
$"<ErrorMessage>{this.ErrorMessage ?? string.Empty}</ErrorMessage>" +
$"<RedirectUrl>{this.RedirectUrl ?? string.Empty}</RedirectUrl>" +
$"<Status>CancelWithError</Status>" +
$"</ProcessEventResult></ProcessEventResponse></s:Body></s:Envelope>";
This articles might help too:
https://spblog.net/post/2021/09/14/how-to-use-remote-event-receivers-with-net-core-or-net-5-and-pnp-framework
https://www.linkedin.com/pulse/sharepoint-remote-event-receivers-using-azure-function-rakhi-jain