Icon not displaying for internet shortcut windows 7 on desktop

628 Views Asked by At

I am creating Internet shortcut using the following code. But the icon of the shortcut which I am setting is not getting displayed in the case of desktop. But if I am manually renaming the shortcut to some other name its working fine(icon is getting loaded as shortcut image).

private String CreateDeskTopShortcut(String ApplicationStartupUrl, String IconFilePath)
{
    string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    String UrlPath = deskDir + "\\" + "Test" + ".url";

    using (StreamWriter writer = new StreamWriter(UrlPath))
    {
        writer.WriteLine("[InternetShortcut]");
        writer.WriteLine("URL=" + ApplicationStartupUrl);
        writer.WriteLine("IconFile=" + IconFilePath);
        writer.WriteLine("IconIndex=0");
        writer.Flush();
    }

    return UrlPath;
}

calling the same as

CreateDeskTopShortcut("https://ipAddress/website/Login.aspx","E:\Setup_Local\Server.ico");
1

There are 1 best solutions below

1
On BEST ANSWER

It looks like Windows caches the icon path, and this persists even if you delete the file. I have no idea where this cache is stored, or if it persists beyond a reboot. My reproduction steps were as follows:

  1. Call CreateDeskTopShortcut("http://www.google.co.uk", "\path\to.ico");
  2. Shortcut created with expected icon.
  3. Delete shortcut and call CreateDeskTopShortcut("http://www.google.co.uk", "\other-path\to.ico");
  4. Shortcut created, but with icon from step 1.
  5. Change shortcut name from 'Test' to 'Test2'. Repeat step 3.
  6. Shortcut created, with expected icon.

So the icon used seems to be mapped to the name of the shortcut.