Tag Archives: dialogs

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

savefiledialog in vb.net

 
Following example shows how to use savefiledialog for selecting the path for saving the file in vb.net.

Private Sub Button1_Click(ByVal sender As System.Object, _
                     ByVal e As System.EventArgs) Handles Button1.Click
    Dim objDlg As SaveFileDialog = New SaveFileDialog()
    Dim objDlgResult As DialogResult = objDlg.ShowDialog()
    If objDlgResult = Windows.Forms.DialogResult.OK Then
        'write your code
    End If
End Sub