- Create Project for Remote Event Receiver
- Need to type “USER ACCOUNT” and “PASSWORD” –> Choose “SharePoint Online” –> “Next”
- Change the Properties of the Project (SharePointAddIn1)
- Handle Add-in Install –> “True”
- Handle Add-in Uninstall –> “True”
- When you change the properties ( Handle Add-in Install and Handle Add-in Uninstall ), the VS .NET will add Folder called “Services” and .svc file called “AppEventReceiver.svc” under the services folder automatically. This is for Default Lists or Document Libraries.
If you wanna create custom List, you need to add Remote Event Receiver on your own for installation ( Because we need some information of the RER ). As below: ( Add Remote Event Receiver )
- Config the AppManifest.xml and Web.Config
- <StartPage> … </StartPage> –> Point off the Page of the list or Document Library where the RER will be installed on the SharePoint Online. E.g.
- Document Library : Document Library URL
- List : List URL
- ClientId
- Config Permission – AppManifest.xml
- Grant Permission to an App: https://spexptw.sharepoint.com/sites/dev/_layouts/15/appinv.aspx
- App Id ( the same with the Client Id )
- Title: the same with the Title on the (…/_layouts/15/appregnew.aspx)
- App Domain: the same with the App Domain on the (…/_layouts/15/appregnew.aspx)
- Redirect URI: the same with the Redirect Uri on the (…/_layouts/15/appregnew.aspx)
- Permission Request XML ( copy from AppManifest.xml and paste it, then click “OK” ):
<AppPermissionRequests AllowAppOnlyPolicy=”true”>
<AppPermissionRequest Scope=”http://sharepoint/content/sitecollection” Right=”FullControl” />
</AppPermissionRequests>
- Change Web.Config
- ClientId
- ClientSecret
- Add Key ( for debugging )
- <add key=”RERdebuggingServiceBusUrl” value=”https://?????.servicebus.windows.net/3845660891/3839167270/obj/0c454565-deeb-4a44-b8b6-9cce0ff955e1/Services/AppEventReceiver.svc” />
- “Key” comes from “string debugEndpoint = System.ServiceModel.OperationContext.Current.Channel.LocalAddress.Uri.ToString();“ for Debug
- Config Debug ( Right click on the Project name: SamplePnp ) –> click “Properties”
- Microsoft Azure Service Bus connection string ( come from Azure ): Primary Connection String
- Open the “AppEventReceiver.svc.cs“, Add some code inside. /// When the event was triggered, the process will JUST get into this program, event though you add Remote Event Receiver for Custom Lists
/// Simple Example: ProcessEvent mean -ing; ProcessOneWayEvent mean -ed
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
SPRemoteEventResult result = new SPRemoteEventResult();
switch (properties.EventType)
{
case SPRemoteEventType.AppInstalled:
HandleAppInstalled(properties);
break;
case SPRemoteEventType.AppUninstalling:
HandleAppUninstalling(properties);
break;
case SPRemoteEventType.ItemDeleting:
{
result.ErrorMessage = “Enhanced Records Manager prevents classes / folders / parts or records being deleted” +
“, you must use a disposal to remove them.”;
result.Status = SPRemoteEventServiceStatus.CancelWithError;
break;
}
}
return result;
}
{ Question } : If you use the RER for Item deleting
- Problem is that when you delete the item all you get is a blank screen when you do it from a list view.
- The delete is stopped but no message displayed just a blank screen.
- However when you do it from the View Properties page then the delete is stopped and the error message is displayed.
{ Answer } : So now when you install our app it checks for the Minimal Download Strategy ( Site Feature ) and if its activated then deactivates it.
From <https://simpleinnovationassociates.wordpress.com/2015/02/13/display-error-message-from-an-office-365-sharepoint-online-remote-event-receiver/>
Minimal Download Strategy
A technique that delivers a faster and more fluid page navigation experience, in pages and site templates that support it, by downloading and rendering only those portions of a page that are changing.