C# 如何获取可移动磁盘列表?
我想在c#中获取可移动磁盘列表。 我想跳过本地驱动器。 因为我希望用户仅将文件保存在可移动磁盘中。
I want to get the list of removable disk in c#. I want to skip the local drives.
Because i want the user to save the file only in removable disk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要为此方法引用
System.IO
。或者对于 LINQ 粉丝:
已添加
至于保存部分,据我所知,我认为您不能限制允许用户使用 SaveFileDialog 保存的位置,但您可以在显示 SaveFileDialog 后完成检查。
或
最好的选择是创建您自己的保存对话框,其中包含树视图,仅显示可移动驱动器及其内容供用户保存! 我会推荐这个选项。
希望这可以帮助
You will need to reference
System.IO
for this method.Or for the LINQ fans:
Added
As for the Saving part, as far as I know I don't think you can restrict where the user is allowed to save to using a SaveFileDialog, but you could complete a check after you have shown the SaveFileDialog.
OR
The best option would be to create your own Save Dialog, which contains a tree view, only showing the removable drives and their contents for the user to save to! I would recommend this option.
Hope this helps
怎么样:
How about:
您还可以使用 WMI 获取可移动驱动器列表。
根据评论进行编辑:
获取驱动器列表后,获取 GUID 并将它们添加到 SaveFileDialogInstance.CustomPlaces 集合中。
下面的代码需要一些调整......
You can also use WMI to get the list of removable drives.
Edited based on comment:
After you get the list of drives get there GUID's and add them to SaveFileDialogInstance.CustomPlaces collection.
The code below need some tweaking...