I am trying to create a remote event receiver that I can apply to an existing SharePoint list.
My initial motivation for doing that was because I couldn't get the List I created in my SharePoint App to display picture URLs as images rather than hyperlinks. I figured that out: you can edit the Schema.xml for the List object with the XML editor,
search for the <Field> object for the field, and add Format="Image" to it.
However, I'm still not entirely satisfied with deploying the List in the SharePoint App. Some of the functionality (like editing the Edit form and the Display form in InfoPath) aren't present in the List Ribbon for a List deployed as a SharePoint app.
I suspect there's a way to customize those in the SharePoint app as well, but right now I'd rather just add behavior to an OOTB SharePoint list if I can.
I have created a Remote Event Listener and tested it on my SharePoint App List:
I have created an App Catalog on my SharePoint 365 dev installation:
I am now trying to use the Remote Event Listener on an arbitrary list in my root page:
As part of that, I added support for running code when my SharePoint App is installed using an App Event Receiver:
I added code in the AppInstalled handler to find the list I want to add the RER to and add a receiver to it:
void InstallRemoteEventReceiver(ClientContext context) {
var list = context.Web.Lists.GetByTitle("Picture Reference");
InstallForEvent(EventReceiverType.ItemAdded, list);
InstallForEvent(EventReceiverType.ItemUpdated, list);
context.ExecuteQuery();
}
void InstallForEvent(EventReceiverType receiverType, List list) {
var eventReceiver = new EventReceiverDefinitionCreationInformation {
ReceiverName = receiverType + "OnPlantUpdated",
EventType = receiverType, ReceiverAssembly = Assembly.GetExecutingAssembly().FullName,
ReceiverClass = "OnPlantUpdated",
ReceiverUrl = "https://mysite.sharepoint.com/Services/AppEventReceiver.svc", SequenceNumber = 1000
};
list.EventReceivers.Add(eventReceiver);
}
The RER does not appear to run when I add or edit an item in my "Picture Reference" list.
I suspect the problem is the path to the svc file in ReceiverUrl, although (since I can't really debug it) I have no idea. I'm sure there could be any number of things that I could be doing wrong that would prevent the RER from running.
Here are some the values I've tried for ReceiverUrl without success:
- ~remoteAppUrl/Services/OnPlantUpdated.svc
- ~remoteAppUrl/Services/AppEventReceiver.svc
- ~remoteAppUrl/OnPlantUpdated.svc
- ~remoteAppUrl/AppEventReceiver.svc
- OnPlantUpdated.svc
- AppEventReceiver.svc
- https://mysite.sharepoint.com/OnPlantUpdated.svc
- https://mysite.sharepoint.com/AppEventReceiver.svc
- https://mysite.sharepoint.com/Services/OnPlantUpdated.svc
- https://mysite.sharepoint.com/Services/AppEventReceiver.svc
The Url tag specified in Elements.xml for the RER is ~remoteAppUrl/Services/OnPlantUpdated.svc:
<Receiver><Name>OnPlantUpdatedItemAdding</Name><Type>ItemAdding</Type><SequenceNumber>10000</SequenceNumber><Url>~remoteAppUrl/Services/OnPlantUpdated.svc</Url></Receiver>
The InstalledEventEndpoint specified in AppManifest.xml is ~remoteAppUrl/Services/AppEventReceiver.svc. So I wasn't quite sure what the deployed .svc file name would actually be.
I also tried packaging the app and deploying it to my App Catalog, in case the issue was that the service URL wouldn't be available while the app was simply in the "Apps in Testing" list. That didn't seem to help either.
I used SharePoint Designer 2013 to look at "All Files" for the site, and didn't see the svc file in there.
So my main question is: where does the service file live when the app is published?
And the secondary question is: anyone see anything wrong with this approach?
Thanks,
David Cater