0

I am using the FolderBrowseDialog in my Vb,Net Windows Form to ask the user to locate where a specific file is on their computer but I only want to allow local drives and not Network Drives.

Does anyone know of a way to prevent Network Drives from showing in the FolderBrowseDialog or stop them from been selected.

Ian Barber
  • 133
  • 8
  • Do you mean mapped network drives? You can pass the FBD SelectedPath to DriveInfo: `var dInfo = new DriveInfo(fbd.SelectedPath); if (dInfo.DriveType == DriveType.Network) { ... }`. Show a warning and present the dialog again. – Jimi Aug 25 '20 at 18:30
  • When trying that code, it threw an exception. {"Object must be a root directory (""C:\"") or a drive letter (""C"")."} System.Exception {System.ArgumentException} – Ian Barber Aug 25 '20 at 18:44
  • 2
    Well, I posted it in C# for some reason. You may not have adapt it to VB.Net (and your existing code) as it should be: `Using fbd As New FolderBrowserDialog() fbd.RootFolder = Environment.SpecialFolder.MyComputer If fbd.ShowDialog() = DialogResult.OK Then dim dInfo as new DriveInfo(fbd.SelectedPath) if dInfo.DriveType = DriveType.Network then [...] End If End If End Using` – Jimi Aug 25 '20 at 19:05
  • Thank You, Having never used DriveType before that has led me to start reading on it so I can fully understand your example. Once again thanks for pointing me in the right direction. – Ian Barber Aug 25 '20 at 19:23

0 Answers0