Question

How to get the deleted file when itemDeleted event fire in remote event receiver in SharePoint Online.

I have tried as follows but this does not work:

List photos = clientContext.Web.Lists.GetById(properties.ItemEventProperties.ListId);
ListItem item = photos.GetItemById(properties.ItemEventProperties.ListItemId);
string filename = Convert.ToString(item["FileLeafRef"]);
Was it helpful?

Solution

Use ItemDeleting event instead of ItemDeleted if you want to get the file which is to be deleted. For ItemDeleted event List Item properties are not available.

SharePointEventReceiver

OTHER TIPS

ItemDeleted Event will trigger after the file has been deleted, if you want to get file which will be deleted, use ItemDeleting instead:

SharePoint Remote Event Receiver – Item Deleting – Using Provider hosted App

You can get deleted item as follows.

  var fileurl = properties.ItemEventProperties.BeforeUrl;
    string[] nFileName = fileurl.Split('/');
    var fileName = nFileName[1]; 
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top