在打开文件对话框中仅打开本地驱动器 [英] Open only local drives in open file dialog

查看:31
本文介绍了在打开文件对话框中仅打开本地驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开一个OpenFileDialog",我们只能在上面选择本地硬盘驱动器(例如 C:\,D:).我想添加访问网络驱动器的限制.我使用了以下代码,但我可以访问网络驱动器.

I want to open a "OpenFileDialog", on which we can select only local hard drives (ex. C:\,D:). I want to add restrictions to access network drives. I have used following code but I am able to access the network drive.

代码如下:

OpenFileDialog dialog = new OpenFileDialog();
            dialog.CustomPlaces.Clear();
            foreach (DriveInfo Drive in DriveInfo.GetDrives())
            {
                if (Drive.DriveType == DriveType.Fixed)
                {
                    dialog.CustomPlaces.Add(Drive.Name);
                }
            }
            dialog.ShowDialog();

推荐答案

我认为内置的 OpenfileDialog.更改 CustomPlaces 只是您想要固定在左上角的自定义"位置列表.它不限制他们可以去的地方.

I don't think this is possible with the built-in OpenfileDialog. Changing the CustomPlaces is just the list of "custom" places you want pinned on the top left. It doesn't limit the places they can go.

我认为你要么编写一个自定义对话框(ick!),要么在他们点击确定后做一些事情来验证他们的选择.

I think you'll have to either write a custom dialog (ick!) or do something to validate their selection after they've hit ok.

这篇关于在打开文件对话框中仅打开本地驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆