msbg
msbg

Reputation: 4962

How to create an internet shortcut with an icon in c#?

I want to create an internet shortcut (url file) with a custom icon on the desktop. To create the shortcut, I currently use:

    private void CreateShortcut(string name, string url)
    {
        string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

        using (StreamWriter writer = new StreamWriter(deskDir + "\\" + name + ".url"))
        {
            writer.WriteLine("[InternetShortcut]");
            writer.WriteLine("URL=" + url);
            writer.Flush();
        }
    }

But this code does not set a custom icon. How would I set the icon?

Upvotes: 6

Views: 7223

Answers (1)

max
max

Reputation: 34407

Set IconIndex and IconFile parameters:

[InternetShortcut]
URL=<url>
IconIndex=0
IconFile=<path to custom icon icon file>

Upvotes: 10

Related Questions