/// <summary>
/// This will create a Application Reference file on the users desktop
/// if they do not already have one when the program is loaded. Place this in the applicatoin
/// main or any other section of code that is run when the application opens.
// If not debugging in visual studio check for Application Reference
// #if (!debug)
// CreateShortcut();
// #endif
/// </summary
void CreateShortcut()
{
ApplicationDeployment application = ApplicationDeployment.CurrentDeployment;
if (ApplicationDeployment.IsNetworkDeployed && application.IsFirstRun)
{
Assembly code = Assembly.GetExecutingAssembly();
string company = string.Empty;
string description = string.Empty;
if (Attribute.IsDefined(code, typeof(AssemblyCompanyAttribute)))
{
AssemblyCompanyAttribute asssemblyCompany =
(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(code,
typeof(AssemblyCompanyAttribute));
company = asssemblyCompany.Company;
}
if (Attribute.IsDefined(code, typeof(AssemblyDescriptionAttribute)))
{
AssemblyDescriptionAttribute assemblyDescription =
(AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code,
typeof(AssemblyDescriptionAttribute));
description = assemblyDescription.Description;
}
if (!string.IsNullOrEmpty(company) && !string.IsNullOrEmpty(description))
{
string desktopPath = string.Concat(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"\\", description, ".appref-ms");
string shortcutName = string.Concat(
Environment.GetFolderPath(Environment.SpecialFolder.Programs),
"\\", company, "\\", description, ".appref-ms");
File.Copy(shortcutName, desktopPath, true);
}
}
}