Click to See Complete Forum and Search --> : Folder Picker


Andrew R.
July 4th, 2001, 05:01 PM
Is there such thing in VB as Folder Picker?
I know there is a CommonDialog control, but it has only FileOpen/Save standard dialogs. :-(

Raptors Fan
July 4th, 2001, 05:40 PM
What about the DirListBox control... have you tried that?

shree
July 4th, 2001, 07:22 PM
private Type SHITEMID
cb as Long
abID as Byte
End Type

private Type ITEMIDLIST
mkid as SHITEMID
End Type

private Type BROWSEINFO
hOwner 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 Const BIF_RETURNONLYFSDIRS = &H16
private Const MAX_PATH = 260
private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(byval hwndOwner as Long, _
byval nFolder as Long, _
Pidl as Long) as Long


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 Declare Sub CoTaskMemFree Lib "ole32.dll" (byval pv as Long)

private Function vbGetBrowseDirectory() as string
Dim bi as BROWSEINFO
Dim IDL as ITEMIDLIST
Dim R as Long
Dim Pidl as Long
Dim tmpPath as string
Dim pos as Integer

bi.pidlRoot = 0&
bi.lpszTitle = "Select input files location"
bi.ulFlags = BIF_RETURNONLYFSDIRS 'get the folder
Pidl = SHBrowseForFolder(bi)

If Pidl <> 0 then
tmpPath = Space$(MAX_PATH)
If SHGetPathFromIDList(Pidl, byval tmpPath) then
pos = InStr(tmpPath, Chr$(0))
tmpPath = Left(tmpPath, pos - 1)
vbGetBrowseDirectory = ValidateDir(tmpPath)
else:
vbGetBrowseDirectory = ValidateDir("c:\")
End If
else
vbGetBrowseDirectory = ValidateDir("c:\")
End If
Call CoTaskMemFree(Pidl)

End Function

private Function ValidateDir(tmpPath as string) as string
If Right$(tmpPath, 1) = "\" then
ValidateDir = tmpPath
else
ValidateDir = tmpPath & "\"
End If
End Function

private Sub Command1_Click()
vbGetBrowseDirectory
End Sub

Andrew R.
July 5th, 2001, 10:16 AM
the code has a bug - it shows domain names in the network but cannot explore them :-(

TH1
July 5th, 2001, 10:51 AM
You can use the BrowseDialog OCX available at the common conrols replacement project http://www.mvps.org/ccrp