Get selected folder from Folder Browser Dialog using vb.net

 
Following example code demonstrate how to get selected path from folder browser dialog in vb.net.

Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        Dim SelectedPath As String = GetSelectedPath()
End Sub
Private Function GetSelectedPath() As String
        Dim objDlg As New FolderBrowserDialog
        Dim SelectedPath As String = ""
        'Set The Folderbrowserdialog Control Properties
        objDlg.Description = "Select Your  Folder"
        objDlg.RootFolder = Environment.SpecialFolder.MyDocuments
        objDlg.ShowNewFolderButton = True
        If objDlg.ShowDialog = Windows.Forms.DialogResult.OK Then
 
            SelectedPath = objDlg.SelectedPath
        End If
        'Clean Up
        objDlg.Dispose()
        objDlg = Nothing
        Return SelectedPath
End Function
  • Luqman

    Hi, thanks for the code. Its really help me.

  • raghu

    thank u very much nice working well