wpf 公司网络上的 FolderBrowserDialog 以选择子文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35033606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FolderBrowserDialog on company network to select subfolder
提问by Frank
In my WPF app the user needs to select a folder, which path is in the company network. I use the System.Windows.Forms.FolderBrowserDialogand the following code gets executed on a button click event:
在我的 WPF 应用程序中,用户需要选择一个文件夹,该文件夹位于公司网络中。我使用System.Windows.Forms.FolderBrowserDialog并且在按钮单击事件上执行以下代码:
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.SelectedPath = "\\company.net\data\_Confidential";
DialogResult result = fbd.ShowDialog();
When the FolderBrowserDialogopens, the system automatically scans for other network devices and that causes the following problem:
当FolderBrowserDialog打开时,系统会自动扫描其他网络设备并导致以下问题:
The network tree gets filled with other devices and causes my SelectedPathto scroll away. This is pretty annoying when a user starts searching for a special subfolder, because he has to scroll down or his selection clicks can hit a newly added device (lost focus).
网络树被其他设备填满并导致我SelectedPath滚动离开。当用户开始搜索特殊的子文件夹时,这非常烦人,因为他必须向下滚动,否则他的选择点击可能会击中新添加的设备(失去焦点)。
How can i avoid this problem?
我怎样才能避免这个问题?
Thoughts:
想法:
- Can I extend/overwrite the
System.Environment.SpecialFolderEnum and setfbd.RootFolder = System.Environment.SpecialFolder.MySepcialNetworkPath; - Should I access the network folder with another dialog/control?
- Should I remove the "Browse..."
Buttonin my View and instead scan the whole\\\\company.net\\data\\_Confidentialpath and provide a combobox/other selection control(e.g. own subfolder-tree)?
- 我可以扩展/覆盖
System.Environment.SpecialFolderEnum 并设置fbd.RootFolder = System.Environment.SpecialFolder.MySepcialNetworkPath; - 我应该使用另一个对话框/控件访问网络文件夹吗?
- 我应该删除
Button视图中的“浏览...” ,而是扫描整个\\\\company.net\\data\\_Confidential路径并提供组合框/其他选择控件(例如自己的子文件夹树)?
回答by Maarten van Stam
The FolderBrowserDialog is 'adopting' your PC settings depending on how your Network Discovery is configured on your PC/network. By doing so your folder browsing experience will be consistent over other applications.
FolderBrowserDialog 正在“采用”您的 PC 设置,具体取决于您的网络发现在您的 PC/网络上的配置方式。通过这样做,您的文件夹浏览体验将与其他应用程序保持一致。
Although what you see is default behavior of the FolderBrowserDialog, you may also look at this: https://stackoverflow.com/a/15440926/5793786Solved an issue somewhat similar to yours @Frank
虽然您看到的是 FolderBrowserDialog 的默认行为,但您也可以看看这个:https: //stackoverflow.com/a/15440926/5793786 解决了一个与您的问题有些相似的问题@Frank
回答by Elmer
While I was searching for the same problem I came across this thread:
当我在寻找同样的问题时,我遇到了这个线程:
How to use OpenFileDialog to select a folder?
Where the user uses a "CommonOpenFileDialog" available in the Nuget Package "WindowsAPICodePack-Shell".
用户使用 Nuget 包“WindowsAPICodePack-Shell”中提供的“CommonOpenFileDialog”。
This solved my issue, though it uses the OpenFileDialog interface.
这解决了我的问题,尽管它使用 OpenFileDialog 接口。
Then the network drive can just be browsed.
然后就可以浏览网络驱动器了。


