How to get list of Files if a parent folder is deleted in Sharepoint?

Yichen Name 46 Reputation points

I am deleting a folder with e.g. 3 files and with current change token, I am getting id of a folder but not the files inside it.
Is there any way with which I can get the file details or just a id?

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
7,022 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
1,968 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 19,726 Reputation points Microsoft Vendor

    Hi @Yichen Name
    Per my test, we are unable to get items from a deleted folder. As a workaround, I will recommend you to use ChangeQuery to get deleted items from a list. Please refer to following code

    ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);  
    Web oweb = ctx.Web;  
    ListCollection lists = oweb.Lists;  
    List targetList = lists.GetByTitle("Coding");  
    //ChangeQuery helps the method gets the changes by setting appropriate property as true  
    ChangeQuery cq = new ChangeQuery();  
    cq.Item = true;  
    //cq.Add = true;  
    //cq.Update = true;  
    cq.DeleteObject = true;  
    ChangeCollection cc = targetList.GetChanges(cq);  
    foreach (Change change in cc)  
        if (change is Microsoft.SharePoint.Client.ChangeItem)  
            ChangeItem ci = change as ChangeItem;  
            ChangeType changeType = ci.ChangeType;  
            var itemId = ci.ItemId.ToString();  
            Console.WriteLine("{0}: {1}", itemId, changeType);  

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.