Selecting a folder using dialog

Hi
 
If I use the MS Common Cialog ocx in order to select a folder I can only select files.
How can i select a folder?

  Amitai
LVL 1
mAmitaiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
samopalConnect With a Mentor Commented:
You can't select a folder using MS Common Dialog. You can do this using DirListBox and DriveListBox on your form.
If you need an example how to use them, let me know.
0
 
EDDYKTCommented:
Try this

Option Explicit
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Private Type BROWSEINFO
    HwndOwner As Long
    PidlRoot As Long
    PszDisplayName As String
    LpszTitle As String
    UlFlags As Long
    Lpfn As Long
    lParam As Long
    IImage As Long
End Type

Private Sub Command1_Click()
    Dim Info As BROWSEINFO
    Dim PID As Long, Path As String, Tmp As String
    Dim localpath As String
     
    Info.HwndOwner = Me.hWnd
    Info.PidlRoot = &H0
    Info.LpszTitle = "Select File Path:"
    Info.UlFlags = &H1
    PID = SHBrowseForFolder(Info)
    Path = Space$(512)
    If (SHGetPathFromIDList(PID, Path)) Then localpath = Left$(Path, InStr(Path, Chr$(0)) - 1)
End Sub

If cancel is pressed, localpath is ""


0
All Courses

From novice to tech pro — start learning today.