FolderBrowserDialog in Visual Basic .NET
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This lesson describes the FolderBrowserDialog control
Visual Basic offers a wide range of dialog boxes that allow the user to make standard selections and each of them has a very specific purpose.
The purpose of the FolderBrowserDialog is selecting a folder (directory).
This control lets the user select a folder (directory) in the file system. The dialog box is displayed by calling the ShowDialog method:
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then ' get the selected path value Dim path As String = FolderBrowserDialog1.SelectedPath ' set the SelectedFolder.Text = path ' ToDo: call the method that populates the Files listview End If
As you see the SelectedPath property returns the path selected by the user, and also determines where the dialog begins browsing.
You can also explicitly set the SelectedPath value to start browsing in a particular folder. For example, the following code makes the dialog begin browsing in the C:\ folder:
FolderBrowserDialog1.SelectedPath = "C:\"
In addition you can always use the RootFolder property to make the component start in one of the system folders e.g.
Private Sub FolderBrowserDialog_Load(sender As Object, e As EventArgs) Handles Me.Load ' set the root folder where the browse start from FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyDocuments End SubPrevious Lesson | Next Lesson