mas*_*san 2 .net c# url favorites internet-explorer
我正在使用.NET 2.0 Visual Studio 2005 C#.
下面的代码从包含书签.url文件的目录中获取IE收藏夹(书签)的文件名
例
../users/favorites/blah.url
但我真正想要的是该文件中的书签URL.
检查文件属性时,在Web文档选项卡中显示文件名和URL.
如何从C#访问它?
码
//the code below just get String like "..../users/favorites/blah.url"
//call the method with the folder path:
//GetFavoriteFiles(Environment.GetFolderPath(Environment.SpecialFolder.Favorites));
private List<String> favFiles = new List<String>();
private void GetFavoriteFiles(String folder)
{
String[] favs = Directory.GetFiles(folder);
favFiles.AddRange(favs);
String[] folders = Directory.GetDirectories(folder);
if(folders != null)
{
foreach(String s in folders)
{
GetFavoriteFiles(s);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我.url 在Notepad ++中打开了一个,这就是我找到的.注意,这是在IE8中生成的.
此页面详细介绍了.url(Internet快捷方式)文件的格式.
[DEFAULT]
BASEURL=http://www.google.com.au/
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://www.google.com.au/
IDList=
IconFile=http://www.google.com.au/favicon.ico
IconIndex=1
Run Code Online (Sandbox Code Playgroud)
您应该能够使用基本StreamReaderIO 轻松解析它.
.url文件的当前格式不是一成不变的,可能会在任何操作系统更新中发生变化.解析这些文件的正确方法是通过CLSID_InternetShortcut COM coclass,使用IUniformResourceLocator和IPropertyStorage.我刚刚将该功能添加到TvGameLauncher,您可以从InternetShortcut文件夹(Apache 2.0许可证)中获取代码.
样品用法:
var shortcut = new InternetShortcutManaged(@"MyShortcut.url");
Console.WriteLine("URL: " + shortcut.Url);
Console.WriteLine("Working dir: " + shortcut.WorkingDir);
Console.WriteLine("Icon file: " + shortcut.IconFile);
Console.WriteLine("Icon index: " + shortcut.IconIndex);
Console.WriteLine("Name: " + shortcut.Name);
Console.WriteLine("Description: " + shortcut.Description);
Console.WriteLine("Comment: " + shortcut.Comment);
Run Code Online (Sandbox Code Playgroud)