Code to allow user to browse to file folder

swu

Active member
Joined
Mar 26, 2005
Messages
33
Programming Experience
1-3
I am looking for sample code to allow a user to browse to a file folder and then return the path of the folder to a text box.

Thanks in advance.

swu
 
Hey swu,

Something like:

VB.NET:
Dim fldrDialog as New FolderBrowserDialog
Dim ChosenPath as String
 
if fldrDialog.ShowDialog = DialogResult.OK then
  ChosenPath = fldrDialog.SelectedPath
end if
 
Use openFileDialog for the purpose and simply join this code to your button (or any other control that calls this dialog)
VB.NET:
[color=blue]With[/color] openFileDialog1
[size=2][color=#0000ff]If[/color][/size][size=2] .ShowDialog() = DialogResult.OK [/size][size=2][color=#0000ff]The[/color][/size][size=2][color=#008000]'showDialog method makes the dialog box visible at run time
[/color][/size][size=2][color=#0000ff]Dim[/color][/size][size=2] FileName [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]String [color=green]'this is optional but i prefer to use it however[/color]
 
[/color][/size][size=2]FileName = .FileName
 
myTextBox.Text = FileName [/size][size=2][color=#008000]'displayig File"s path in textBox
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]If
 
[/color][/size]
[color=blue]End With[/color]
[color=#0000ff][/color]


Regards ;)
 
Back
Top