简体   繁体   English

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

[英]How to display File Browser Dialog path directory on a textbox in VB.NET

Im trying to select a file using the File Browser dialog and displaying the path on a textbox我尝试使用“文件浏览器”对话框选择文件并在文本框中显示路径

for an example "C:\\Program Files"例如“C:\\Program Files”

Here is an example of my code:这是我的代码示例:

 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

When the user chooses a file the file directory should appear on the textbox当用户选择一个文件时,文件目录应出现在文本框中

I'm not a VB dev, but possibly something like this should work:我不是 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM