如何访问 .URL 文件中的 URL 和书签标题?

发布于 2024-11-17 01:50:29 字数 858 浏览 6 评论 0原文

我正在使用 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦屿孤独相伴 2024-11-24 01:50:29

我在 Notepad++ 中打开了 .url,这就是我发现的内容。注意,这是在 IE8 中生成的。
此页面详细介绍了 的格式。 url(互联网快捷方式)文件。

[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

您应该能够使用基本的 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.

[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

You should be able to parse this easily using basic StreamReader IO.

允世 2024-11-24 01:50:29

.url 文件的当前格式并不是一成不变的 并且可能会在任何操作系统更新中发生变化。解析这些文件的正确方法是通过 CLSID_InternetShortcut COM coclass,使用IUniformResourceLocatorIPropertyStorage。我刚刚将该功能添加到 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);

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, using IUniformResourceLocator and IPropertyStorage. I just added that capability to TvGameLauncher, you can take the code from the InternetShortcut folder (Apache 2.0 License).

Sample usage:

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文