如何在VB.NET的文本框中显示文件浏览器对话框路径目录

时间:2018-09-07 14:22:57

标签: c# vb.net textbox directory

我正在尝试使用“文件浏览器”对话框选择文件,并在文本框中显示路径

例如“ C:\ Program Files”

这是我的代码示例:

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles bwrBtn.Click

    If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
        rootTxt.Clear()
        Dim grade As New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
        Dim inFiles As IO.FileInfo() = grade.GetFiles()
        Dim fLinfo As IO.FileInfo
        For Each fLinfo In inFiles
            rootTxt.Text(fLinfo)
        Next

    End If
    'Exit File Directory

End Sub

用户选择文件时,文件目录应出现在文本框中

1 个答案:

答案 0 :(得分:2)

我不是VB开发人员,但可能类似这样的事情:

If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    rootTxt.Clear()
    Dim grade As New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
    Dim inFiles As IO.FileInfo() = grade.GetFiles()
    Dim fLinfo As IO.FileInfo

    Dim directoryPath As string = Path.GetDirectoryName(FolderBrowserDialog1.SelectedPath)

    rootTxt.Text = directoryPath
End If