Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I restore a file from the recycle bin using C#?

Moving files to the recycle bin and emptying the recycle bin are well documented, but how can a file be programmatically restored from the recycle bin?

like image 787
Matt Lacey Avatar asked May 26 '09 15:05

Matt Lacey


2 Answers

There seems not to be a solution in pure C#. You most likely have to resort to P/Invoke. This article presents a solution in C++ using the SHFileOperation API.

like image 70
kay.herzam Avatar answered Oct 14 '22 03:10

kay.herzam


The only other reference to this beyond the previously mentioned link to codeproject that I can see mentions this:

Call SHGetFolderLocation passing CSIDL_BITBUCKET. Then you can manipulate that folder as usual. You'll have to create an interop for the SHGetFolderLocation function.

"CSIDL_BUCKET" being the constant for the virtual RecycleBin folder. The quote is taken from here, and will involve interop with the Windows shell. MSDN also mentions that this function has been deprecated in favour of another in Vista.

like image 39
Xiaofu Avatar answered Oct 14 '22 03:10

Xiaofu