VB.NET FolderBrowserDialog – Pick Folders Easily (2026)

The VB.NET FolderBrowserDialog lets users pick a folder from the file system before your application processes its contents. It displays the standard Windows folder picker, returns the selected path, and optionally restricts the browsing root. This guide covers setup, root folder configuration, new-folder creation, batch processing, and common pitfalls.

Need .NET help?

Building a desktop application?

I've been developing professionally in VB.NET and C# for over 17 years. From folder dialogs to complete WinForms applications, I can help.

What is the FolderBrowserDialog?

The FolderBrowserDialog is a WinForms control from System.Windows.Forms. When you call ShowDialog(), it opens the Windows folder picker. The user navigates the folder tree, selects a folder, and clicks OK. Your code then reads the full folder path from the SelectedPath property.

Use it when:

  • The user should choose an output folder for exports, backups, or reports
  • Your application needs to batch-process all files inside a directory
  • The user should pick an installation or working directory
  • You want to let the user create a new folder on the fly

If the user should pick a single file instead, use the OpenFileDialog. To save a file to a specific location, use the SaveFileDialog.

Basic example

The simplest FolderBrowserDialog that displays the selected path:

Using dlg As New FolderBrowserDialog()
    dlg.Description = "Select a folder"

    If dlg.ShowDialog() = DialogResult.OK Then
        MessageBox.Show($"Selected: {dlg.SelectedPath}")
    End If
End Using

The Using block disposes the dialog after use. ShowDialog() returns DialogResult.OK when the user confirms, or DialogResult.Cancel when they close the dialog. Always check the result before using the path.

Setting the root folder

The RootFolder property restricts which top-level node the dialog shows. It accepts values from Environment.SpecialFolder:

Using dlg As New FolderBrowserDialog()
    ' Only show folders inside Desktop
    dlg.RootFolder = Environment.SpecialFolder.Desktop
    dlg.Description = "Select a project folder"

    If dlg.ShowDialog() = DialogResult.OK Then
        Dim folder As String = dlg.SelectedPath
    End If
End Using

Common values for RootFolder:

  • Environment.SpecialFolder.Desktop (default) shows the full tree starting from Desktop
  • Environment.SpecialFolder.MyComputer shows all drives
  • Environment.SpecialFolder.MyDocuments limits browsing to the Documents folder

Pre-selecting a folder

Use SelectedPath to pre-select a folder when the dialog opens. This is useful when the user already chose a folder earlier and you want to remember it:

Using dlg As New FolderBrowserDialog()
    dlg.Description = "Select export folder"
    dlg.SelectedPath = "C:\Users\Public\Documents"

    If dlg.ShowDialog() = DialogResult.OK Then
        Dim exportFolder As String = dlg.SelectedPath
    End If
End Using

The dialog opens with that folder already highlighted. If the path does not exist, the dialog falls back to the root.

Hiding the New Folder button

By default, the dialog includes a „Make New Folder“ button. If the user should only pick an existing folder, disable it:

Using dlg As New FolderBrowserDialog()
    dlg.Description = "Select an existing folder"
    dlg.ShowNewFolderButton = False

    If dlg.ShowDialog() = DialogResult.OK Then
        Dim folder As String = dlg.SelectedPath
    End If
End Using

Set ShowNewFolderButton = False for read-only operations like importing files. Keep it True (the default) when the user might need to create a destination folder for exports.

Complete example: batch-processing files

A realistic example that lets the user pick a folder and then processes all text files inside it:

Imports System.IO
Imports System.Text

Private Sub BtnImport_Click(sender As Object, e As EventArgs) Handles BtnImport.Click
    Using dlg As New FolderBrowserDialog()
        dlg.Description = "Select folder with text files"
        dlg.ShowNewFolderButton = False

        If dlg.ShowDialog() = DialogResult.OK Then
            Dim files() As String = Directory.GetFiles(
                dlg.SelectedPath, "*.txt")

            For Each filePath In files
                Dim content As String = File.ReadAllText(
                    filePath, Encoding.UTF8)
                ' Process each file...
            Next

            MessageBox.Show($"{files.Length} files processed.")
        End If
    End Using
End Sub

Directory.GetFiles() returns all matching files in the selected folder. Use the second parameter for pattern matching, e.g. "*.csv" or "*.xml". For more on reading text files, see the VB.NET Read Text File guide.

Planning a project?

Need a polished WinForms application?

From file dialogs to complete data-driven desktop apps: I design software that lasts. Let's talk about your project.

Including subfolders

To process files recursively, add SearchOption.AllDirectories:

If dlg.ShowDialog() = DialogResult.OK Then
    Dim files() As String = Directory.GetFiles(
        dlg.SelectedPath, "*.txt", SearchOption.AllDirectories)

    For Each filePath In files
        Dim relativePath As String = filePath.Replace(
            dlg.SelectedPath & "\", "")
        ' Process file with relative path info...
    Next
End If

This searches the selected folder and all its subfolders. Be careful with large directory trees, as this can take a while if there are thousands of files.

Using Environment.SpecialFolder

You can combine the dialog with Environment.GetFolderPath() to pre-select common system folders. You can also use the application path as the starting point:

' Start in Documents
Using dlg As New FolderBrowserDialog()
    dlg.SelectedPath = Environment.GetFolderPath(
        Environment.SpecialFolder.MyDocuments)

    If dlg.ShowDialog() = DialogResult.OK Then
        ' Use dlg.SelectedPath...
    End If
End Using

' Start in the application directory
Using dlg As New FolderBrowserDialog()
    dlg.SelectedPath = Application.StartupPath

    If dlg.ShowDialog() = DialogResult.OK Then
        ' Use dlg.SelectedPath...
    End If
End Using

All important properties at a glance

PropertyDefaultPurpose
Description(empty)Text shown above the folder tree
SelectedPath(empty)Pre-selected folder / selected folder after dialog
RootFolderDesktopTop-level node of the folder tree
ShowNewFolderButtonTrueShow or hide the „Make New Folder“ button

The FolderBrowserDialog has fewer properties than the OpenFileDialog because it only deals with folders, not files. There is no Filter or Multiselect property.

Common mistakes

Using the path without checking DialogResult

' BAD - SelectedPath is empty if user cancels
dlg.ShowDialog()
Dim files = Directory.GetFiles(dlg.SelectedPath)

' GOOD - check the result first
If dlg.ShowDialog() = DialogResult.OK Then
    Dim files = Directory.GetFiles(dlg.SelectedPath)
End If

Confusing RootFolder and SelectedPath

RootFolder limits which folders the user can see. SelectedPath pre-selects a folder within the visible tree. If you set RootFolder = MyDocuments, the user cannot navigate outside of Documents. If you only want to suggest a starting point but allow full navigation, use SelectedPath instead.

Forgetting the Using block

Like all WinForms dialogs, the FolderBrowserDialog holds unmanaged resources. Without Using, those resources stay in memory until the garbage collector runs. Always wrap it in a Using block.

Need expert support?

Looking for an experienced .NET developer?

I'll take on your project, from file operations to finished desktop applications. Just drop me a message.

FAQ

How do I open a FolderBrowserDialog in VB.NET?

Create a New FolderBrowserDialog() inside a Using block, optionally set Description, then call ShowDialog(). Check if the result equals DialogResult.OK before reading dlg.SelectedPath.

How do I set the default folder in FolderBrowserDialog?

Set dlg.SelectedPath to the desired folder path before calling ShowDialog(). The dialog opens with that folder highlighted. Do not confuse this with RootFolder, which restricts the visible tree.

Can I hide the New Folder button?

Yes. Set dlg.ShowNewFolderButton = False before calling ShowDialog(). This is useful for read-only operations where the user should only select an existing folder.

What is the difference between RootFolder and SelectedPath?

RootFolder limits the top-level node the user can browse, restricting navigation. SelectedPath pre-selects a folder within the visible tree without restricting navigation. Use SelectedPath when you want a starting point but full access.

Can the user select multiple folders?

No. The built-in FolderBrowserDialog only supports selecting a single folder. If you need multiple folder selection, you would need to call the dialog multiple times or use a custom solution.

Wrapping up

The FolderBrowserDialog gives your VB.NET application a native folder picker with minimal code. Set SelectedPath to suggest a starting folder, use RootFolder to restrict navigation, and hide the New Folder button with ShowNewFolderButton = False when the user should only select existing folders. After the dialog closes, combine SelectedPath with Directory.GetFiles() to process folder contents. For picking individual files, use the OpenFileDialog. To save files, see the SaveFileDialog.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Robert Skibbe
Datenschutz-Übersicht

Diese Website verwendet Cookies, damit wir dir die bestmögliche Benutzererfahrung bieten können. Cookie-Informationen werden in deinem Browser gespeichert und führen Funktionen aus, wie das Wiedererkennen von dir, wenn du auf unsere Website zurückkehrst, und hilft unserem Team zu verstehen, welche Abschnitte der Website für dich am interessantesten und nützlichsten sind.