Working with FolderBrowserDialog in VB.NET

Posted by Abhisek under VB.NET category on | Views : 4506
Working with FolderBrowserDialog in VB.NET

First create a window application in VB.Net and add a FolderBrowserDialog controll to it. Also add a textbox(txtFolder) and button( btnBrowseFolders).

The button's work here is to open the FolderBrowserDialog and user can select any folder or file to be displayed in the text box. Now double click on the button and add the following code in it.

Private Sub btnBrowseFolders_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowseFolders.Click
With fldlgList
'set the RootFolder
.RootFolder = Environment.SpecialFolder.Personal
' optional Description to provide additional instructions.
Description = "Select the directory you want to use as the default."
ShowNewFolderButton = True
'Showing the selected folder in the textbox
If ShowDialog = Windows.Forms.DialogResult.OK Then
txtFolder.Text = .SelectedPath
End If

End With

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)

End Try

End Sub


After creating a new FolderBrowserDialog, you have to set the RootFolder to the location from which to start browsing. You can choose from the list of system special folders, such as Program Files, Programs, System, or Startup, which contain common information.

RootFolder = Environment.SpecialFolder.Personal

We can give user optional information about the bowser using the Description property.

Description = "Select the directory you want to use as the default."

You can use the ShowNewFolderButton property to control if the user is able to create new folders via the New Folder button in the browse dialogue window.

ShowNewFolderButton = True

Comments or Responses

Login to post response