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

问题描述 投票:-2回答:1

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

例如“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

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

c# vb.net textbox directory
1个回答
2
投票

我不是VB dev,但可能这样的东西应该工作:

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
© www.soinside.com 2019 - 2024. All rights reserved.