Csharp/C#教程:如何访问.URL文件中的URL和书签标题?分享


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

我正在使用.NET 2.0 Visual Studio 2005 C#。

下面的代码从包含书签.url文件的目录中获取IEcollections夹(书签)的文件名

../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 favFiles = new List(); 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); } } } 

我在Notepad ++中打开了一个.url ,这就是我找到的。 注意,这是在IE8中生成的。 此页面详细介绍了.url (Internet快捷方式)文件的格式。

 [DEFAULT] BASEURL=https://www.google.com.au/ [{000214A0-0000-0000-C000-000000000046}] Prop3=19,2 [InternetShortcut] URL=https://www.google.com.au/ IDList= IconFile=https://www.google.com.au/favicon.ico IconIndex=1 

您应该能够使用基本的StreamReader IO轻松解析它。

.url文件的当前格式不是 .url ,可能会在任何操作系统更新中发生变化。 解析这些文件的正确方法是使用IUniformResourceLocatorIPropertyStorage通过CLSID_InternetShortcut COM coclass 。 我刚刚将该function添加到TvGameLauncher ,您可以从InternetShortcut文件夹 (Apache 2.0许可证)中获取代码。

样品用法:

上述就是C#学习教程:如何访问.URL文件中的URL和书签标题?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 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); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1029249.html

(0)
上一篇 2022年1月12日
下一篇 2022年1月12日

精彩推荐