I have the requirement to process a document list item when it is changed by a remote event receiver. The remote event receiver is wired into the itemupdated event. There is an obvious issue with this that I will get stuck in an infintite loop if I update an item in the itemupdated event.
To avoid this infinite loop, and in the absence of something like EventFiringEnabled that I would have used with old school SharePoint development, I thought about adding a "Processed" flag on the list item to indicate that the document has been processed.
The logic flow then looks like this.
- Document is added to library - nothing special here
- Metadata is filled out on list item - ItemUpdated event fires
- Remote event receiver springs into life. Checks the "Processed" flag. If true, do nothing, if false, carry on. Using the metadata on the document, it "Processes" it. Document is updated and list item "Processed" flag is set to true.
The trouble I'm having is updating the document and the list item in a single transaction.
My SaveFile method looks like this:
private void SaveFile(List list, string url, MemoryStream memoryStream)
{
var newFile = new FileCreationInformation
{
ContentStream = memoryStream,
Url = url,
Overwrite = true
};
File updatedFile = list.RootFolder.Files.Add(newFile);
ListItem item = updatedFile.ListItemAllFields;
item["Processed"] = true;
item.Update();
_clientContext.ExecuteQuery();
}
But this manifests itself as two updates. The file is updated, and then the list item is. Does anyone know if I can force this into a single update?