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

Yichen Name 66 Reputation points
2022-11-15T19:54:34.263+00:00

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?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,916 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.
3,098 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 36,421 Reputation points Microsoft Vendor
    2022-11-16T06:49:14.027+00:00

    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);  
    ctx.Load(cc);  
    ctx.ExecuteQuery();  
    Console.WriteLine(cc.Count.ToString());  
    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.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.