Skip to content

Instantly share code, notes, and snippets.

@ezirmusitua
Created November 11, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezirmusitua/36c640ede41a16ea714c5559e8138bde to your computer and use it in GitHub Desktop.
Save ezirmusitua/36c640ede41a16ea714c5559e8138bde to your computer and use it in GitHub Desktop.
[Create desktop shortcut] Create desktop shortcut for one click application #CSharp
// Reference: https://stackoverflow.com/questions/152188/can-i-create-a-desktop-icon-for-a-clickonce-application
// Program Class
private void CreateDesktopIcon () {
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
// create desktop shortcut at first time application run
if (ad.IsFirstRun) {
Assembly assembly = Assembly.GetEntryAssembly ();
// NOTE: Get assembly information and to get Program shortcut in Program File(Generated By OneClick)
string product = string.Empty;
if (Attribute.IsDefined (assembly, typeof (AssemblyProductAttribute))) {
AssemblyProductAttribute asproduct =
(AssemblyProductAttribute) Attribute.GetCustomAttribute (
assembly, typeof (AssemblyProductAttribute));
product = asproduct.Product;
}
if (!string.IsNullOrEmpty (product)) {
string desktopPath = string.Empty;
desktopPath = string.Concat (
Environment.GetFolderPath (Environment.SpecialFolder.Desktop),
"\\",
description,
".appref-ms");
string shortcutName = string.Empty;
shortcutName = string.Concat (
Environment.GetFolderPath (Environment.SpecialFolder.Programs),
"\\",
product,
".appref-ms");
System.IO.File.Copy (shortcutName, desktopPath, true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment