我试图使用“文件浏览器”对话框选择文件并在文本框中显示路径
例如“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
当用户选择文件时,文件目录应出现在文本框中
我不是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