Hi John, you need to do two steps to create the shortcut
firts is necesary create the shortcut, you can use this method:
/// <summary>
/// You need to add a COM reference of Windows Script Host Object Model and
add
/// using IWshRuntimeLibrary;
/// This method was copied of:
///
http://www.geekpedia.com/tutorial125_Create-shortcuts-with-a-.NET-application.html
/// </summary>
private void CreateShortCut(string shortcutPath, string shortcutName, string
documentPath)
{
// Create a new instance of WshShellClass
WshShell wshShell = new WshShell();
// Create the shortcut
IWshRuntimeLibrary.IWshShortcut shortCut;
// Choose the path for the shortcut
shortCut =
(IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutPath);
// Where the shortcut should point to
shortCut.TargetPath = documentPath;
// Description for the shortcut
shortCut.Description = shortcutName;
// Create the shortcut at the given path
shortCut.Save();
}
Next you need invoke the method in the deploy proccess, so you can do it in
Load application event:
/// <summary>
/// This method to check if the application run deployed since ClickOnce and
it is the
/// firts time that the application run
/// You need a reference of System.Deployment.Application
/// </summary>
private bool CheckForShortcut()
{
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
if (ad.IsFirstRun)
{
string dataPath = ad.DataDirectory;
if (System.IO.File.Exists(ad.DataDirectory + @"\Document.doc"))
{
MessageBox.Show("Creating shortcut...");
string shortcutPath =
string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"\\", "Document", ".lnk");
string shortcutName = "06_05_2007_Articulo_MAGEUI.doc";
string documentPath = ad.DataDirectory +
@"\06_05_2007_Articulo_MAGEUI.doc";
CreateShortCut(shortcutPath, shortcutName, documentPath);
return true;
}
}
}
return false;
}
private void ShortCut_Load(object sender, EventArgs e)
{
if (CheckForShortcut())
MessageBox.Show("ShortCuts added");
}
I hope to help you!
Gustavo Hurtado
http://gahurtado.blogspot.com