Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim bookmarks = GetBookmarks() ListBox1.Items.Clear() For Each title In bookmarks.Keys Dim url = bookmarks(title) ListBox1.Items.Add(title & " - " & url) Next End Sub Public Function GetBookmarks() As Dictionary(Of String, String) 'お気に入りの階層を無視してフラットにお気に入りを取得する例 Dim results As New Dictionary(Of String, String) Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites) For Each fileName As String In IO.Directory.GetFiles(path, "*.url", IO.SearchOption.AllDirectories) Dim title As String = IO.Path.GetFileNameWithoutExtension(fileName) Dim lines As String() = IO.File.ReadAllLines(fileName) Dim url As String = lines.First(Function(line) line.StartsWith("URL=")) results(title) = Replace(url, "URL=", "") Next Return results End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListBox1.Items.AddRange(GetBookmarks.ToArray) End Sub Public Function GetBookmarks() As List(Of WebSiteLink) 'お気に入りの階層を無視してフラットにお気に入りを取得する例 Dim results As New List(Of WebSiteLink) Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites) For Each fileName As String In IO.Directory.GetFiles(path, "*.url", IO.SearchOption.AllDirectories) Dim title As String = IO.Path.GetFileNameWithoutExtension(fileName) Dim lines As String() = IO.File.ReadAllLines(fileName) Dim url As String = lines.First(Function(line) line.StartsWith("URL=")) Dim link As New WebSiteLink With {.Title = title, .URL = Replace(url, "URL=", "")} results.Add(link) Next Return results End Function Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim bookmarks = GetBookmarks() ListBox1.Items.Clear() For Each bookmark In bookmarks ListBox1.Items.Add(bookmark) Next End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim link As WebSiteLink = ListBox1.SelectedItem Process.Start(link.URL.ToString) End Sub Public Class WebSiteLink Public Title As String Public URL As String Public Overrides Function ToString() As String Return Title End Function End Class