HOW TO CREATE AN INTERNET SHORTCUT WITH AN ICON IN C#?

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
C# 
C#
 4512  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. Pravesh Singh

    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>

Answer

NEWSLETTER

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