Share via


Is there a way to download file directly from recycle bin?

Question

Wednesday, July 3, 2019 5:57 AM

I found two endpoints to work with SharePoint recycle bin.

_api/web/recyclebin

_api/web/recyclebin(' + ID + ')

none of them provide the physical address for me to grab the item directly.

Is there a way that I have grab the items from the recycle bin directly without restoring it and downloading it in the original location?

Thanks.

All replies (7)

Wednesday, July 3, 2019 9:00 AM âś…Answered | 2 votes

Hi Six Eggs,

You can do this thru the small coding , to locate the Recycle Bin you can code as below:

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

For detailed examples of downloading the file you can refer the below links which 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

You can give more focus on the second link.

To identify whether the item in  Recycle bin files, folder or document  set , you can use the below code:

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();
        }
    }

Added more information

If we want to automate this as a regular routine job then we can do any of the below:

Approach 1:

Make the above C# code as batch file and configure this as windows job which will run in configured interval.

Approach 2:

We can handle this thru MS flow trigger , whenever any item is coming to Recycle bin we can call "

"Copy files from SharePoint to your PC" action in MS flow, this will download the items in your local drive. 

To trigger this action we can think of "Send HTTP Request to SharePoint" action this should be configured before "Copy files from SharePoint to your PC" action. 

**Example of send http request flow action: **

https://www.chakkaradeep.com/2018/05/16/working-with-the-sharepoint-send-http-request-flow-action/

Copy files from SharePoint to your PC Template Url:

https://india.flow.microsoft.com/en-us/galleries/public/templates/efe45e60e00811e6b070f5b13cd24608/copy-files-from-sharepoint-to-your-pc/

Note: To locate the Recyle Bin folder we  can use the below REST API end point:

REST API ( /_api/web/RecycleBin )

Thanks&Regards,

Habibur Rahaman

MCSA,MCP,MCTS

Note: If you feel the proposed answer is helpful, please mark as so or if this answered your question,please mark as answer.


Wednesday, July 3, 2019 6:12 AM

Try downloading to a drop box or cloud.


Wednesday, July 3, 2019 8:44 AM

Thank you for your reply. Can you give me some detail on how to download it to other destination? Seems there is no option to move the content of recycle bin to other locations except restore.


Thursday, July 4, 2019 3:05 AM | 1 vote

Hi,

I did test in my local environment and checked official document below, there is no OOB api to get file stream from RecycleBinItem, so you have to restore it and then downloading according to my knowledge.

/en-us/previous-versions/office/sharepoint-server/ee541897(v%3Doffice.15)

Best Regards,

Lee

Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact [email protected].

SharePoint Server 2019 has been released, you can click

here to download it.
Click

here to learn new features. Visit the dedicated

forum to share, explore and talk to experts about SharePoint Server 2019.


Thursday, July 4, 2019 9:02 AM

Hi Six Eggs,

If my post answer your question - can you please mark it as answered.

Thanks&Regards,

Habibur Rahaman

MCSA,MCP,MCTS

Note: If you feel the proposed answer is helpful, please mark as so or if this answered your question,please mark as answer.


Friday, July 5, 2019 9:05 AM

Hi Habibur,

Thank you for your answer. However, I am not developing my app with CSOM. Is there other ways to do this? 


Friday, July 5, 2019 12:45 PM

Hi Six Eggs,

You can try out the REST API and MS flow approach which I have  mentioned above.

Thanks&Regards,

Habibur Rahaman

MCSA,MCP,MCTS

Note: If you feel the proposed answer is helpful, please mark as so or if this answered your question,please mark as answer.