Trying to create several different shortcuts for different desktop URLs using the following method:
public static void CreateShortcutWithURL(
string shortcutName, string shortcutPath, string targetFileLocation)
{
var shortcutLocation = Path.Combine(shortcutPath, shortcutName + ".lnk");
var shell = new WshShell();
var shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.TargetPath = $" \" {targetFileLocation} \" https://www.somewebsite.com";
shortcut.Save();
}
Errors if I try to add anything to targetFileLocation.
I use it as follows:
CreateShortcutWithURL(
"My Shortcut",
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
@"C:\Program Files (x86)\Internet Explorer\iexplore.exe");
If I change this line in the method to this, it will end without errors:
shortcut.TargetPath = targetFileLocation ;
The shortcut is placed on the desktop, but without the additional https://www.somewebsite.com added to the target, so it simply opens the browser without directing it to the website.
I am trying to create several shortcuts that open Explorer but make it navigate to certain websites.
Hanny source
share