I am trying to programatically create a shortcut to a directory. I have found numerous examples, but none appear to work realiably.
I observe three different results in the produced shortcut's properties:
The Shortcut Type of File is assigned as "Shortcut(.lnk)" which cause the Open With dialog box to pop up asking me to attach an extension to it.
The Shortcut Type of File property is assigned as "File" which does absolutely nothing when double clicked.
Or lastly which is of course my favorite... the Shortcut Type of File property is assigned as: "File Folder" which works like it should.
Here is the code I am currently using... I've tried a few variations of this.
bool IsExists = false;
string icon = appPath + "Welcome.ico";
// Their is a difference to local and ClickOnce App locations... this compensates for it
IsExists = System.IO.File.Exists(icon);
if (!IsExists)
{
icon = appPath + @"bin\Debug\Welcome.ico";
}
var desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
var target = (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artronix\Welcome To FreightWare Online\").Replace(@"\","/");
IWshShortcut shortcut;
var wshShell = new WshShellClass();
shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(desktop, @"FreightWare Resources.lnk"));
shortcut.IconLocation = icon;
shortcut.TargetPath = Path.GetFullPath(target);
shortcut.Save();