Link to home
Start Free TrialLog in
Avatar of iflash2
iflash2

asked on

How to Display Open Directory Dialogue Box

Hi all,

Instead of of selecting a file, I'm trying to let the user select a directory in a dialogue box.

Thank you
Avatar of VBtorment
VBtorment

Hai,

Use the FolderBrowser object from the toolbar, then use this code:

        FolderBrowserDialog1.SelectedPath = "C:\TEMP"
        FolderBrowserDialog1.ShowNewFolderButton = True
        FolderBrowserDialog1.Description = "Select folder..."
        FolderBrowserDialog1.ShowDialog(Me)
        If FolderBrowserDialog1.ShowDialog(Me) = DialogResult.OK Then
            TextBox2.Text = FolderBrowserDialog1.SelectedPath
        End If
Avatar of iflash2

ASKER

Hi VBtorment,

I think im using the older version of VB.NET (2002)... there is no FolderBrowserDialog box.. is there another way to do this?
ASKER CERTIFIED SOLUTION
Avatar of armoghan
armoghan
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Use OpenFileDialog control and add the following code.


Dim OpenDig As New OpenFileDialog()
        OpenFileDialog1.Title = "Title of the Dialog Box"
        OpenFileDialog1.DefaultExt = ".doc"
        OpenFileDialog1.ShowDialog
        End If
koolnurd's answer looks about right, just thought id add what to do after your user has selected a file.

Once the user has selected a file, you can retrieve the path of the file/folder selected using OpenFileDialog1.FileName

Then you can instruct your app to do whatever you require using that path.

Jaz
I dont agree with jazduck, Directory selection is a separate thing.
If you do not have a file in the directory in koolnurd method you cannt select that directory
Your right armoghan, i misread the question slightly.  OpenFileDialog would be correct to select a file, not a folder.
Accept Armoghan