Results 1 to 4 of 4

Thread: How do I make a network location the selected path in a folder browser dialog?

  1. #1

    Thread Starter
    Lively Member Christhemist's Avatar
    Join Date
    Sep 2016
    Location
    Nevada
    Posts
    116

    How do I make a network location the selected path in a folder browser dialog?

    I am building an application that will allow users to select a folder on our file server. I want the folder browser dialog default location to be a certain folder on our file server. So far I can only get the folder browser to work locally. Is this possible? Also, If I can get the folder browser dialog to scroll down to this folder that would be great!

    Path I want to use: \\FileServer\Folder

    Here is the code I have so far:

    Code:
    Private Sub Button12_Click_1(sender As Object, e As EventArgs) Handles Button12.Click
            FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
            FolderBrowserDialog1.SelectedPath = "\\FileServer\Folder"
            If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
                MsgBox(FolderBrowserDialog1.SelectedPath)
            End If
        End Sub

  2. #2
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    774

    Re: How do I make a network location the selected path in a folder browser dialog?

    I did a quick search and found this thread (on this forum):

    http://www.vbforums.com/showthread.p...ith-a-UNC-path

    This suggests what you are trying should work, so what error are you getting?

  3. #3

    Thread Starter
    Lively Member Christhemist's Avatar
    Join Date
    Sep 2016
    Location
    Nevada
    Posts
    116

    Re: How do I make a network location the selected path in a folder browser dialog?

    That link worked! I think this line was screwing me up:

    Code:
    FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
    How do I get it to expand that folder now? And scroll down to it?

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: How do I make a network location the selected path in a folder browser dialog?

    Don't set RootFolder *and* SelectedPath, or be more careful when doing so. They're related to each other, and by setting them both you make it impossible to achieve your goal.

    RootFolder is "the root folder where browsing starts from". This, in fact, can restrict what appears in the dialog. For example, if I pick Program Files, you'll ONLY be able to see folders that are inside Program Files with the dialog.

    SelectedPath is more or less "the folder that is currently selected". It isn't guaranteed to be on the screen, and may not even be valid.

    So if I set RootFolder to "Program Files", but set SelectedPath to "C:\Windows", what happens is I get a FolderBrowserDialog that is rooted at "C:\Program Files" but has no visible selection. If I dismiss it without selecting a folder, SelectedValue will STILL be "C:\Windows", but if I select anything it will have changed.

    You can't see network paths because they are not located under "My Computer" in the hierarchy. This sort of makes sense, in that folders with paths like that usually exist on OTHER computers. When you set SelectedPath, the network location can't be displayed since it's in a different hierarchy, so it looks like it's broken.

    So you need to set RootFolder to something that can display network locations, and the only one I can find is "Desktop". My guess is if you do that (or just let it stay at the default value, which is "Desktop") you'll have more success.

    As for scrolling it into view, it looks like that is fairly involved and requires some API calls because someone in Microsoft was asleep at the wheel when designing the behavior.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width