如何访问 .URL 文件中的 URL 和书签标题?
我正在使用 .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);
}
}
}
I'm using .NET 2.0 Visual Studio 2005 C#.
The code below gets file name of the IE favorites (bookmark) from the directory that contains bookmarked .url files
Example
../users/favorites/blah.url
But what I really want is the bookmarked URL inside of that file.
When check the file property, in the web document tab, it shows filename and URL.
How can I access it from C#?
CODE
//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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 Notepad++ 中打开了
.url
,这就是我发现的内容。注意,这是在 IE8 中生成的。此页面详细介绍了
的格式。 url
(互联网快捷方式)文件。您应该能够使用基本的 StreamReader IO 轻松解析它。
I opened a
.url
in Notepad++ and this is what I found. Note, this was generated in IE8.This page has a detailed look into the format of the
.url
(internet shortcut) file.You should be able to parse this easily using basic
StreamReader
IO..url
文件的当前格式并不是一成不变的 并且可能会在任何操作系统更新中发生变化。解析这些文件的正确方法是通过 CLSID_InternetShortcut COM coclass,使用IUniformResourceLocator
和IPropertyStorage
。我刚刚将该功能添加到 TvGameLauncher,您可以从 InternetShortcut 文件夹 (Apache 2.0 执照)。使用示例:
The current format of a
.url
file is not set in stone and could change in any OS update. The right way to parse these files is via the CLSID_InternetShortcut COM coclass, usingIUniformResourceLocator
andIPropertyStorage
. I just added that capability to TvGameLauncher, you can take the code from the InternetShortcut folder (Apache 2.0 License).Sample usage: