CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2008
    Posts
    74

    open a folder and select a file

    hi,
    i need know how can i open a folder and select a file that is inside of that folder
    like windows does when we choose a option to locate a shorcut file
    thanks a lot for your help

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: open a folder and select a file

    You could use the command line switches in the explorer. Something like this should work
    Code:
        Dim filePath As String
        filePath = "C:\Folder\FileName.txt"
        Shell "Explorer /select," & Chr(34) & filePath & Chr(34), vbMaximizedFocus

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: open a folder and select a file

    No, I think what you seek is the CommonDialog control.
    Add 'Microsoft CommonDialog Control 6.0' to your toolbox and put one on your form.
    It allows to create a FileOpen dialog like windows uses to allow for the selection of a file somewhere on a drive.
    If you need to know more details, CommonDialog is described in the VB online manual.
    The most simple usage:
    Put a CommonDialog on a form. Name it "cdlg"
    In a button put the code: cdlg.ShowOpen to see if that's what you wanted.
    You can walk through the folders and select a file, and after clicking ok it returns to your calling routine and cdlg.FileName contains the selected filename.
    Very easy.

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: open a folder and select a file

    Duh!
    I thought OP was talking about the select. But yes I agree, what he needs is a Common Dialog control which can be added to the control toolbox using the above procedure mentioned in post # 3.

  5. #5
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: open a folder and select a file

    You can also set the initial directory and one or more filters via code before you call the show open method. This way if you want them to be able to browse images only you can filter by image type or set of image types using wildcards. e.g. *.jpg *.bmp on so on

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

Featured