Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 833
msbg Avatar asked Feb 19 '23 20:02

msbg


1 Answers

Set IconIndex and IconFile parameters:

[InternetShortcut]
URL=<url>
IconIndex=0
IconFile=<path to custom icon icon file>
like image 94
max Avatar answered Mar 03 '23 01:03

max