问题
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:
- Call CreateDeskTopShortcut("http://www.google.co.uk", "\path\to.ico");
- Shortcut created with expected icon.
- Delete shortcut and call CreateDeskTopShortcut("http://www.google.co.uk", "\other-path\to.ico");
- Shortcut created, but with icon from step 1.
- Change shortcut name from 'Test' to 'Test2'. Repeat step 3.
- 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