How to set selected folder in FolderBrowserDialog in vb.net

You can set the selected path of the folder browser dialog with the help of Selectedpath() property.

Example:

The following code creates an Folder browser dialog with selected path “c:\Test”.

Private Sub SetSelectedFolder()
        Dim objFolderDlg As System.Windows.Forms.FolderBrowserDialog
        objFolderDlg = New System.Windows.Forms.FolderBrowserDialog
        objFolderDlg.SelectedPath = "C:\Test"
        If objFolderDlg.ShowDialog() = DialogResult.OK Then
            MessageBox.Show(objFolderDlg.SelectedPath)
        End If
End Sub

If the ShowDialog returns OK, meaning the user clicked the OK button, the SelectedPath property will return a string containing the path to the selected folder. If ShowDialog returns Cancel, meaning the user canceled out of the dialog box