按名称获取子文件夹并将 Web 浏览器导航到该路径
Get subfolder by name and navigate Webrowser to that path
我的组合框将文件夹名称(位于我的 C:\ 子文件夹中)作为项目。我想根据组合框中的 selected 文件夹名称来浏览我的 Web 浏览器。这是我尝试过的:
Dim myDirectories = Directory.GetDirectories("C:\", MyCombo.Text, SearchOption.AllDirectories)
WebBrowser1.Navigate(myDirectories)
我必须如何搜索子文件夹才能完成这项工作?我收到错误:"The address specified cannot exist." in webrowser control.
编辑(让自己更清楚一点):
Example - 有一个名为 Test 的文件夹和一个名为 Example.... ]
I select "Test" 或 "Example" 来自组合框项目;
然后通过代码,Webrowser 应该导航到我电脑上的那个文件夹 URL。
所以代码应该像在 Combobox 中那样通过名称搜索所有 folders/subfolders,然后如果有匹配条件则将路径传递给 Webbrowser URL。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strFiles As String() = IO.Directory.GetDirectories("C:\")
For Each sDir As String In strFiles
ListBox1.Items.Add(sDir)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.Items.Count > -1 Then
Process.Start("explorer", ListBox1.SelectedItem.ToString)
End If
End Sub
已解决。我就是这样做的,欢迎提出更好的建议:
Dim myDirectory = Directory.GetDirectories("C:\", MyCombo.Text, SearchOption.AllDirectories)
For Each folder As String In myDirectory
WebBrowser1.Navigate(folder)
Next
为什么要对本地路径使用 Web 浏览器? Web 浏览器用于 Internet,这就是为什么您在查找 http 而不是 c:\.
时收到错误消息的原因
用组合框代替列表框
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strFiles As String() = IO.Directory.GetDirectories("C:\")
For Each sDir As String In strFiles
ComboBox1.Items.Add(sDir)
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Items.Count > -1 Then
Process.Start("explorer", ComboBox1.SelectedItem.ToString)
End If
End Sub
如果您愿意,可以使用该列表框来保存所选目录中的文件列表,这将完全删除 Web 浏览器控件
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim strFiles As String() = Nothing
If ComboBox1.Items.Count > 0 Then
strFiles = IO.Directory.GetFiles(ComboBox1.SelectedItem.ToString)
ListBox1.Items.Clear()
For Each sFile As String In strFiles
ListBox1.Items.Add(IO.Path.GetFileName(sFile))
Next
End If
End S
我的组合框将文件夹名称(位于我的 C:\ 子文件夹中)作为项目。我想根据组合框中的 selected 文件夹名称来浏览我的 Web 浏览器。这是我尝试过的:
Dim myDirectories = Directory.GetDirectories("C:\", MyCombo.Text, SearchOption.AllDirectories)
WebBrowser1.Navigate(myDirectories)
我必须如何搜索子文件夹才能完成这项工作?我收到错误:"The address specified cannot exist." in webrowser control.
编辑(让自己更清楚一点):
Example - 有一个名为 Test 的文件夹和一个名为 Example.... ]
I select "Test" 或 "Example" 来自组合框项目;
然后通过代码,Webrowser 应该导航到我电脑上的那个文件夹 URL。
所以代码应该像在 Combobox 中那样通过名称搜索所有 folders/subfolders,然后如果有匹配条件则将路径传递给 Webbrowser URL。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strFiles As String() = IO.Directory.GetDirectories("C:\")
For Each sDir As String In strFiles
ListBox1.Items.Add(sDir)
Next
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.Items.Count > -1 Then
Process.Start("explorer", ListBox1.SelectedItem.ToString)
End If
End Sub
已解决。我就是这样做的,欢迎提出更好的建议:
Dim myDirectory = Directory.GetDirectories("C:\", MyCombo.Text, SearchOption.AllDirectories)
For Each folder As String In myDirectory
WebBrowser1.Navigate(folder)
Next
为什么要对本地路径使用 Web 浏览器? Web 浏览器用于 Internet,这就是为什么您在查找 http 而不是 c:\.
时收到错误消息的原因用组合框代替列表框
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim strFiles As String() = IO.Directory.GetDirectories("C:\")
For Each sDir As String In strFiles
ComboBox1.Items.Add(sDir)
Next
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Items.Count > -1 Then
Process.Start("explorer", ComboBox1.SelectedItem.ToString)
End If
End Sub
如果您愿意,可以使用该列表框来保存所选目录中的文件列表,这将完全删除 Web 浏览器控件
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim strFiles As String() = Nothing
If ComboBox1.Items.Count > 0 Then
strFiles = IO.Directory.GetFiles(ComboBox1.SelectedItem.ToString)
ListBox1.Items.Clear()
For Each sFile As String In strFiles
ListBox1.Items.Add(IO.Path.GetFileName(sFile))
Next
End If
End S