简体   繁体   中英

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"

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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