Search code examples
c#.netinternet-explorerurlfavorites

How to access URL and bookmark title in .URL files?


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

Solution

  • 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.