How to get deleted file when itemDeleted event fire in remote event receiver
-
08-02-2021 - |
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"]);
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.
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