I'm working on a remove event receiver which when triggered by an ItemDeleting event should copy the list item (file) from the original document library to another.
Please see a code below for reference:
private void HandleItemDeleting(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties)) { if (clientContext != null) { var documentLibraryName = properties.ItemEventProperties.ListTitle; var documentLibraries = clientContext.LoadQuery(clientContext.Web.Lists.Where(l => l.Title == documentLibraryName)); clientContext.ExecuteQuery(); var documentLibrary = documentLibraries.FirstOrDefault(); if (documentLibrary == null) { return; } var archiveDocumentLibraryName = properties.ItemEventProperties.ListTitle + " - Archive"; var archiveDocumentLibraries = clientContext.LoadQuery(clientContext.Web.Lists .Where(l => l.Title == archiveDocumentLibraryName)); clientContext.ExecuteQuery(); var archiveDocumentLibrary = archiveDocumentLibraries.FirstOrDefault(); if (archiveDocumentLibrary == null) { return; } //** insert code here to copy file (item) from documentLibrary to archiveDocumentLibrary **// } } } Note that the purpose of the code above is to help illustrate the problem and can be modified as long as it solves the original intent of copying the file triggering the event to another document library.
What is the best way to accomplish this?