如何使用 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(3)
纯C#似乎没有解决方案。 您很可能必须求助于 P/Invoke。
本文使用 SHFileOperation API。
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.
除了前面提到的 codeproject 链接之外,我可以找到的唯一其他参考看到提到这一点:
CSIDL_BITBUCKET
是 CSIDL(“常量特殊项”) ID 列表”)虚拟回收站文件夹的值。 引用摘自此处,并且将涉及与 Windows shell 的互操作。 MSDN 还提到此功能已被弃用支持 Vista 中的另一个。The only other reference to this beyond the previously mentioned link to codeproject that I can see mentions this:
CSIDL_BITBUCKET
being the CSIDL ("constant special item ID list") value for the virtual Recycle Bin 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.希望下面的代码能够恢复文件。 请确保 STA 调用仅支持 shell 调用
Hope below code will work to restore the files. Please make sure, STA Calls only supported for shell calls