dcsimg
Results 1 to 4 of 4

Thread: How can I select a UNC path using DirListBox or Common Dialog

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Location
    Atlanta, Georgia
    Posts
    81

    How can I select a UNC path using DirListBox or Common Dialog

    Using VB5, I need my users to be able to select a directory where I will place a backup of their data (an MDB). DirListBox does not show Network Places, it only shows drives attached to the computer being used. Common Dialog seems to only allow me to select a file, not a directory.
    Does anyone know of some magic code I can slip in there that will use some Windows routine?

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,067

    Re: How can I select a UNC path using DirListBox or Common Dialog

    VB5 is pretty explicitly unsupported at any level since Windows XP. Some people have gotten VB5 programs to run on modern OSs by installing the runtime libraries needed but it remains a dicey proposition.

    In any case, the simplest way to do what you are asking for is probably:

    Code:
    Option Explicit
    
    Private Enum BIF_OPTIONS_ENUM
        'Some options require later shell32.dll versions than 4.71
        BIF_RETURNONLYFSDIRS = &H1&
        BIF_DONTGOBELOWDOMAIN = &H2&
        BIF_RETURNFSANCESTORS = &H8&
        BIF_EDITBOX = &H10&
        BIF_VALIDATE = &H11&
        BIF_NEWDIALOGSTYLE = &H40&
        BIF_BROWSEINCLUDEURLS = &H80&
        BIF_USENEWUI = BIF_EDITBOX Or BIF_NEWDIALOGSTYLE
        BIF_UAHINT = &H100&
        BIF_NONEWFOLDERBUTTON = &H200&
        BIF_NOTRANSLATETARGETS = &H400&
        BIF_BROWSEFORCOMPUTER = &H1000&
        BIF_BROWSEFORPRINTER = &H2000&
        BIF_BROWSEINCLUDEFILES = &H4000&
        BIF_SHAREABLE = &H8000&
    End Enum
    
    Private Const ssfDESKTOP = 0
    
    Private Sub Command1_Click()
        Dim Folder As Object
    
        With CreateObject("Shell.Application")
            Set Folder = .BrowseForFolder(hWnd, _
                                          "Pick a folder", _
                                          BIF_RETURNONLYFSDIRS _
                                       Or BIF_BROWSEINCLUDEURLS _
                                       Or BIF_NONEWFOLDERBUTTON _
                                       Or BIF_NEWDIALOGSTYLE _
                                       Or BIF_UAHINT, _
                                          ssfDESKTOP)
            If Folder Is Nothing Then
                MsgBox "Cancled"
            Else
                MsgBox Folder.Self.Path
            End If
        End With
    End Sub

    Name:  sshot1.png
Views: 75
Size:  6.4 KB

    Name:  sshot2.png
Views: 66
Size:  1.3 KB
    Attached Files Attached Files

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,067

    Re: How can I select a UNC path using DirListBox or Common Dialog

    Here is a more elaborate version of the same thing that offers a few advantages. You can do things like have it "open" at the last used path (or any specific path), change the caption of the "Ok" button, and a few other useful things.

    Note that with both versions you can choose another root, such as ssfNETWORK/CSIDL_NETWORK instead of ssfDESKTOP (local filesystem root).
    Attached Files Attached Files

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2007
    Location
    Atlanta, Georgia
    Posts
    81

    Re: How can I select a UNC path using DirListBox or Common Dialog

    Quote Originally Posted by dilettante View Post
    Here is a more elaborate version of the same thing that offers a few advantages. You can do things like have it "open" at the last used path (or any specific path), change the caption of the "Ok" button, and a few other useful things.

    Note that with both versions you can choose another root, such as ssfNETWORK/CSIDL_NETWORK instead of ssfDESKTOP (local filesystem root).
    Amazing code....I tried the project, as is first, and it worked great. I moved the code into my main project and I had to make a couple of changes so far but it looks like it will be great. Your code is sooo far over my head, it's almost like reading Chinese but not quite. I'm learning from it.
    Hopefully I'll have it fully integrated into my code by tomorrow. It's used in only two places and both of them are in the main project.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width