2

In my WPF app the user needs to select a folder, which path is in the company network. I use the System.Windows.Forms.FolderBrowserDialog and the following code gets executed on a button click event:

        FolderBrowserDialog fbd = new FolderBrowserDialog();
        fbd.SelectedPath = "\\\\company.net\\data\\_Confidential";
        DialogResult result = fbd.ShowDialog();

FolderBrowserDialog on start

When the FolderBrowserDialog opens, the system automatically scans for other network devices and that causes the following problem:

FolderBrowserDialog after 3 seconds

The network tree gets filled with other devices and causes my SelectedPath to 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).

How can i avoid this problem?

Thoughts:

  • Can I extend/overwrite the System.Environment.SpecialFolder Enum and set fbd.RootFolder = System.Environment.SpecialFolder.MySepcialNetworkPath;
  • Should I access the network folder with another dialog/control?
  • Should I remove the "Browse..." Button in my View and instead scan the whole \\\\company.net\\data\\_Confidential path and provide a combobox/other selection control(e.g. own subfolder-tree)?
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Frank
  • 1,113
  • 3
  • 14
  • 27
  • you could filter the network tree by searching in that list for the wanted name. – Zippy Jan 27 '16 at 09:39
  • Is it necessary to use `System.Windows.Forms.FolderBrowserDialog`? Why don'y you use simple `OpenFileDialog`? http://www.wpf-tutorial.com/dialogs/the-openfiledialog/ – StepUp Jan 27 '16 at 10:07
  • 1
    @StepUp `FolderBrowserDialog` because i have to get the name of the folder and than set the `InitialDirectory` of the next `Microsoft.Win32.OpenFileDialog` to the selected folder. Furthermore can the `OpenFileDialog` be used with empty folders? – Frank Jan 27 '16 at 10:14

2 Answers2

0

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.

Although what you see is default behavior of the FolderBrowserDialog, you may also look at this: https://stackoverflow.com/a/15440926/5793786 Solved an issue somewhat similar to yours @Frank

Community
  • 1
  • 1
Maarten van Stam
  • 1,901
  • 1
  • 11
  • 16
0

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".

This solved my issue, though it uses the OpenFileDialog interface.

Then the network drive can just be browsed.

Community
  • 1
  • 1
Elmer
  • 384
  • 5
  • 19