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

Total Post:110

Points:776
C# 
C#
 5175  View(s)
Ratings:
Rate this:

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?

  1. Post:412

    Points:2888
    Re: How to create an internet shortcut with an icon in c#?

    Hi Jeet,


    Set IconIndex and IconFile parameters:

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

      Modified On Apr-04-2018 03:48:53 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!