ClickOnce Shortcut

G

Guest

Hello,

I have some Word documents I deploy to my users via ClickOnce along with the
application files. Unfortunately, I can find no way to put a shortcut in the
Start Menu's Program group for the user to click (I can only show the
application file and the website support shortcut). Could you please tell me
how I could add a shortcut to the data file into the my program's Program
group?

Thanks for your help.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top