Icon not displaying for internet shortcut windows 7 on desktop

試著忘記壹切 提交于 2019-12-12 04:50:24

问题


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:


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.



来源:https://stackoverflow.com/questions/27601312/icon-not-displaying-for-internet-shortcut-windows-7-on-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!