Results 1 to 7 of 7

Thread: [RESOLVED] common dialog

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    23

    Resolved [RESOLVED] common dialog

    Is there a way to use the common dialog control just to get a folder's application path, I also need to create new folders in the dialog box.

    Thanks in advance.

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: common dialog

    What's a folder's application path?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    23

    Re: common dialog

    Sorry I mean of course if I click on a folder I want to return the folders name, when you use commendialog you can create a new folder but you can only receive the name on a file not on a folder.

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: common dialog

    do you want to get the name and path of the "folder" you selected using commondialog or the name of the "file"??

    Harsh Gupta
    Show Appreciation. Rate Posts.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    23

    Re: common dialog

    I want to get the name and path of the "folder" I selected, but I also need to be able to create a new one from the dialog box.

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: common dialog

    using common dialog, it is too complicated because you cannot select a folder through it. but you can use it by selecting one file inside that folder:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim iPath$
    3.    
    4.     cd.ShowOpen
    5.     iPath = Mid$(cd.FileName, 1, InStrRev(cd.FileName, "\"))
    6.    
    7.     'Path and Name of folder
    8.     MsgBox "Path of the folder is: " & iPath
    9.     MsgBox "Name of the folder is: " & Split(iPath, "\")(UBound(Split(iPath, "\")) - 1)
    10.    
    11.     'Path and name of file
    12.     MsgBox "Path of the file is: " & cd.FileName
    13.     MsgBox "Name of the file is: " & cd.FileTitle
    14. End Sub
    common dialog has in-built "Create New Folder" Button next to "View Desktop" button.

    Alternative method - recommended
    use BrowseforFolder API, it will help you in selecting only folder, and return the path of the folder. (just a bit of coding and you may get the name of the folder yourself, not difficult):
    VB Code:
    1. Private Type BrowseInfo
    2.     hWndOwner As Long
    3.     pIDLRoot As Long
    4.     pszDisplayName As Long
    5.     lpszTitle As Long
    6.     ulFlags As Long
    7.     lpfnCallback As Long
    8.     lParam As Long
    9.     iImage As Long
    10. End Type
    11. Const BIF_RETURNONLYFSDIRS = 1
    12. Const MAX_PATH = 260
    13. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
    14. Private Declare Function lstrcat Lib "kernel32" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
    15. Private Declare Function SHBrowseForFolder Lib "shell32" (lpbi As BrowseInfo) As Long
    16. Private Declare Function SHGetPathFromIDList Lib "shell32" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
    17. Private Sub Form_Load()
    18.     'KPD-Team 1998
    19.     'URL: [url]http://www.allapi.net/[/url]
    20.     Dim iNull As Integer, lpIDList As Long, lResult As Long
    21.     Dim sPath As String, udtBI As BrowseInfo
    22.  
    23.     With udtBI
    24.         'Set the owner window
    25.         .hWndOwner = Me.hWnd
    26.         'lstrcat appends the two strings and returns the memory address
    27.         .lpszTitle = lstrcat("C:\", "")
    28.         'Return only if the user selected a directory
    29.         .ulFlags = BIF_RETURNONLYFSDIRS
    30.     End With
    31.  
    32.     'Show the 'Browse for folder' dialog
    33.     lpIDList = SHBrowseForFolder(udtBI)
    34.     If lpIDList Then
    35.         sPath = String$(MAX_PATH, 0)
    36.         'Get the path from the IDList
    37.         SHGetPathFromIDList lpIDList, sPath
    38.         'free the block of memory
    39.         CoTaskMemFree lpIDList
    40.         iNull = InStr(sPath, vbNullChar)
    41.         If iNull Then
    42.             sPath = Left$(sPath, iNull - 1)
    43.         End If
    44.     End If
    45.  
    46.     MsgBox sPath
    47. End Sub
    to add a New folder, if you are using XP, then it would be not much problem. please take a look at this post.
    you may notice that this also a new method of doing it.

    of you are using Win 98, then it is very tricky, but take look at this thread.

    hope it helps you.

    Harsh Gupta
    Show Appreciation. Rate Posts.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2005
    Posts
    23

    Re: common dialog

    Thank you, just what I look for.

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