none
Download Recycle Bin data from Sharepoint online using CSOM C# RRS feed

  • Question

  • Hi,

    I want to download Recycle bin data from sharepoint online using CSOM C#.

    What I know that by following code I will be able to connect to recycle bin.

         Web web = clientContext.Web; 
         RecycleBinItemCollection rbiColl = web.RecycleBin; 
         clientContext.Load(rbiColl);  
         clientContext.ExecuteQuery(); 
         foreach (RecycleBinItem rbiItem in rbiColl) 
         {
            Console.WriteLine(rbiItem.Title);
         } 

    But my question is how to download the recycle bin whole data to my local directory.

    Thanks

    Palak Jain

    Thursday, November 10, 2016 10:17 AM

Answers

  • Hi ,

    You can check this thread that describes how it can be done

    http://sharepoint.stackexchange.com/questions/173449/sharepoint-online-c-csom-download-file
    
    http://stackoverflow.com/questions/17057074/how-to-download-upload-files-from-to-sharepoint-2013-using-csom/21056425
    

    The second URL provides the utility function that will help you download the file from SP Online using CSOM.

    Thanks,

    Priyan


    Please Up Vote and Mark this as Answer if it helps.

    Thursday, November 10, 2016 12:34 PM

All replies

  • Hi Palak,

    You are on the right path. What you need to do , is - 

    1. Check if the recycle bin item as file or a folder

    2 . If its a folder, then loop again

    3. If its a file, then get its extension. 

    4. Convert the file into bytes, and save  the file on your disk 

    Hope this helps.

    Thanks

    Kailas

    ---------------------------------------

    Please Vote or Mark as Answer

    Thursday, November 10, 2016 10:37 AM
  • Hi ,

    You can check this thread that describes how it can be done

    http://sharepoint.stackexchange.com/questions/173449/sharepoint-online-c-csom-download-file
    
    http://stackoverflow.com/questions/17057074/how-to-download-upload-files-from-to-sharepoint-2013-using-csom/21056425
    

    The second URL provides the utility function that will help you download the file from SP Online using CSOM.

    Thanks,

    Priyan


    Please Up Vote and Mark this as Answer if it helps.

    Thursday, November 10, 2016 12:34 PM
  • Hi Kailas,

    Thanks for the reply. But. how you can check if recycle bin item is file or folder. RecycleBinItem doesn't have any property to indicate if it is list, file or folder

    Thanks

    Palak Jain

    Wednesday, November 16, 2016 3:41 AM
  • Hi Palak,

    you can use RecycleBinItemType field to get the type of recycle bin item. please see the below code classifies RecycleBinItemType  is List, Folder, Document, etc. Hope this helps.

     static void Main(string[] args)
            {
                string siteUrl = " ";
                ClientContext clientContext = new ClientContext(siteUrl);
                Site collSite = clientContext.Site;
                RecycleBinItemCollection collRBI = collSite.RecycleBin;
    
                clientContext.Load(collRBI);
                clientContext.ExecuteQuery();
    
                if (collRBI.Count > 0)
                {
                    RecycleBinItem rbiItem = collRBI[0];
                    Console.WriteLine("Title: {0}", rbiItem.Title);
                    Console.WriteLine("Item ID: {0}", rbiItem.Id);
                    Console.WriteLine("Item Type ", rbiItem.ItemType);
                    if (rbiItem.ItemType == RecycleBinItemType.List)
                    {
                        Console.WriteLine("THis is List or Document Library");
                    }
                    else if (rbiItem.ItemType == RecycleBinItemType.File)
                    {
                        Console.WriteLine("This is a file");
    
                    }
                    else if (rbiItem.ItemType == RecycleBinItemType.App)
                    {
                        Console.WriteLine("This is a Site");
    
                    }
                }
                else
                {
                    Console.WriteLine("The Recycle Bin is empty.");
                }
                Console.ReadLine();
            }
        }


    Wednesday, November 16, 2016 6:39 AM
  • Hi Ponvannan,

    Thanks for the reply. After identifying it as a file or a list, how  you can download it. Means, if I want to download file, first I have to convert recycleBinItem to file and then after calling file.OpenBinaryStream() or if it is list then converting recycleBinItem to List. How to do it?

    Thanks,

    Palak Jain


    • Edited by PalakJn Wednesday, November 16, 2016 10:12 AM
    Wednesday, November 16, 2016 7:25 AM
  • Hi Palak Jain,

    I hope there is no direct option to convert recycleBinItem to file. You can try DataConverter class and convert into XML Steam and store. This is a workaround.

    Thanks,

    Pons

    Wednesday, November 16, 2016 10:58 AM
  • Hi Palak 

    I have a similar requirement .Can you please let me know if you are able to download the document from Recycle bin to your file share 


    Anil Kuchi

    Tuesday, August 1, 2017 10:10 PM
  • Hi,

    Has this been tested and working, I worked through it but no success.

    Please let me know.

    Thanks in advance.

    Tuesday, September 17, 2019 10:18 AM