Sharepoint Rest API - getChanges to get list of deleted files when deleting the parent folder
Category
- [x] Question
- [ ] Typo
- [ ] Additional article idea
Question
I have Document library with folders hierarchy , I'm deleting folder. Inside the folder there about 20 fles, I want to get list of all files (items) that were in the deleted folder. This the request URL :
https://domain.sharepoint.com/sites/TestSite/_api/web/Lists(guid'32d6ed0-51ab-4b4d-ab5b-afdd231f1d2e')/getChanges
And the request body is :
"query": {
"Add":true,
"Update":true,
"Rename":true,
"Item":true,
"DeleteObject":true,
"ChangeTokenStart": {
"StringValue": "1;3;32d6ed0-51ab-4b4d-ab5b-afdd231f1d2e;637290302157600000;159531544"
}
}
}
The response contains only information about folder (ItemID = 32) , but doesn't include any information about deleted files:
{
"d": {
"results": [
{
"__metadata": {
"id": "https://domain.sharepoint.com/sites/TestSite/_api/SP.ChangeItem654725d4-6567-145a-b48c-4eef2a21cd00",
"uri": "https://domain.sharepoint.com/sites/TestSite/_api/SP.ChangeItem654725d4-6567-145a-b48c-4eef2a21cd00",
"type": "SP.ChangeItem"
},
"ChangeToken": {
"__metadata": {
"type": "SP.ChangeToken"
},
"StringValue": "1;3;32d6ed0-51ab-4b4d-ab5b-afdd231f1d2e;159531565"
},
"ChangeType": 3,
"SiteId": "xxxx-e0acb7dbeef3",
"Time": "2020-06-29T12:24:25Z",
"Editor": "",
"EditorEmailHint": null,
"ItemId": 32,
"ListId": "32d6ed0-51ab-4b4d-ab5b-afdd231f1d2e",
"ServerRelativeUrl": "",
"SharedByUser": null,
"SharedWithUsers": null,
"UniqueId": "xxx-2fa48d7f9736",
"WebId": "xxx-5487a53e92d5"
}
]
}
}
I would expect to get list of deleted items as well, as they're actually deleted. Is there any way to get list of those delete files ?
Thanks
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
I observing same behaviour, very strange, nested items should be notified in changes log as deleted, this behaviour seems like a bug and hurt entire changes log idea, as to find what files were deleted need to do a full scan.
Does someone from Microsoft looking in that issues list at all ?
I am also having the same issue using CSOM SDK for .NET. (c#)
When a folder is deleted, if I use getChanges for get the information of the deleted items (folder and files), the response only contains the deleted folder. The response doesn't include the deleted files.
Is there any way to get the deleted files?
I think the only way to get the deleted file is using RecycleBin in Sharepoint.. But even I don't see proof of working code
RecycleBinItemCollection collRBI = cxt.Site.RecycleBin;
cxt.Load(collRBI);
cxt.ExecuteQuery();
int deletedfileCount = collRBI.Count;
for (int i = 0; i < deletedfileCount; i++)
{
RecycleBinItem rbiItem = collRBI[i];
recycleBinState =Convert.ToString(rbiItem.ItemState);
if (recycleBinState == "FirstStageRecycleBin")
{
deletedFileNames.Add(rbiItem.LeafName);
}
}
this is working for me..
Make sure that you gave below permission: <AppPermissionRequests AllowAppOnlyPolicy="true"><AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" /></AppPermissionRequests>