2

I want when user runs my c# application , the application will create a desktop shortcut to run application. I use this code :

private void appShortcutToDesktop(string linkName)
{
    string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

    using (StreamWriter writer = new StreamWriter(deskDir + "\\" + linkName + ".url"))
    {
        string app = System.Reflection.Assembly.GetExecutingAssembly().Location;
        writer.WriteLine("[InternetShortcut]");
        writer.WriteLine("URL=file:///" + app);
        writer.WriteLine("IconIndex=0");
        string icon = app.Replace('\\', '/');
        writer.WriteLine("IconFile=" + icon);
        writer.Flush();
    }
}

private void button1_Click(object sender, EventArgs e)
{
    appShortcutToDesktop("MyName");
}

This code creates shortcut but I want to put myicon.ico for shortcuts icon . how can I do this ?

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
SoheilYou
  • 907
  • 5
  • 23
  • 43
  • possible duplicate of [Create shortcut on desktop C#](http://stackoverflow.com/questions/4897655/create-shortcut-on-desktop-c-sharp) – David Arno Jul 17 '15 at 09:19
  • I saw this ,this did now help me ! – SoheilYou Jul 17 '15 at 09:32
  • Replace `writer.WriteLine("IconFile=" + icon);` with `writer.WriteLine("IconFile=" + pathToMyIconDotIco);` – David Arno Jul 17 '15 at 09:37
  • @DavidArno error : The name 'pathToMyIconDotIco' does not exist in the current context c:\users\soheil\documents\visual studio 2012\Projects\shortcut\shortcut\Form1.cs – SoheilYou Jul 17 '15 at 09:47
  • Well of course it doesn't. You have to create it! :) Apologies if that wasn't clear. It's the path of your `myicon.ico` file. – David Arno Jul 17 '15 at 09:56

1 Answers1

6

You can use the following steps:

  1. Right click on your project in the Solution Explorer and select Properties.
  2. Application tab
  3. Icon and manifest
  4. Select icon
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109