Created
November 11, 2019 06:05
-
-
Save ezirmusitua/36c640ede41a16ea714c5559e8138bde to your computer and use it in GitHub Desktop.
[Create desktop shortcut] Create desktop shortcut for one click application #CSharp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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