Geeks With Blogs

News

Google My Blog


Murray Gordon Flash a-ah! Savior of the universe...

Here's a great post on how to add a desktop shortcut to ClickOnce Deployed Application. (Scott Schecter's post)
http://blog.scottschecter.net/TheZenOfTheClickOnceDeployedApplicationDesktopShortcut.aspx

Here's the version of this solution in VB. (Julia Lerman's post)
http://blog.ziffdavis.com/devlife/archive/2006/07/28/42695.aspx

If you don't want to follow the link, here's the code:

/// <summary>

/// This will create a Application Reference file on the users desktop

/// if they do not already have one when the program is loaded.

//    If not debugging in visual studio check for Application Reference

//    #if (!debug)

//        CheckForShortcut();

//    #endif

/// </summary

void CheckForShortcut()

{

    ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

 

    if (ad.IsFirstRun)

    {

        Assembly code = Assembly.GetExecutingAssembly();

 

        string company = string.Empty;

        string description = string.Empty;

 

        if (Attribute.IsDefined(code, typeof(AssemblyCompanyAttribute)))

        {

            AssemblyCompanyAttribute ascompany = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(code,

                typeof(AssemblyCompanyAttribute));

            company = ascompany.Company;

        }

 

        if (Attribute.IsDefined(code, typeof(AssemblyDescriptionAttribute)))

        {

            AssemblyDescriptionAttribute asdescription = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code,

                typeof(AssemblyDescriptionAttribute));

            description = asdescription.Description;

        }

 

        if (company != string.Empty && description != string.Empty)

        {

            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),

                "\\", company, "\\", description, ".appref-ms");

 

            System.IO.File.Copy(shortcutName, desktopPath, true);

        }

 

    }

}

Hope it helps out.

Thanks,
Murray

Posted on Wednesday, October 4, 2006 7:04 PM Visual Studio 2005 , .NET Framework 2.0 , Visual Dev - Client Application Development , Visual Dev - Solutions Architecture | Back to top


Comments on this post: How to add Desktop Shortcut to ClickOnce Deployment Application

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
can anybody tell me where to put that code in the project ???
i am having no idea !!!
Left by vampire on Jun 11, 2007 6:48 AM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
put it in the application event for startup, or anywhere you want it to run
Left by Brandon on Jan 04, 2008 1:08 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Here is the VB, i had to change the company and description part to work properly with the directories of my installation

' <summary>
' This will create a Application Reference file on the users desktop
' if they do not already have one when the program is loaded.
' If not debugging in visual studio check for Application Reference
' #if (!debug)
' CheckForShortcut();
' #endif
' </summary

Private Sub CheckForShortcut()
Dim ad As System.Deployment.Application.ApplicationDeployment
ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment

If (ad.IsFirstRun) Then
Dim code As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim company As String = String.Empty
Dim description As String = String.Empty

If (Attribute.IsDefined(code, GetType(System.Reflection.AssemblyCompanyAttribute))) Then
Dim ascompany As System.Reflection.AssemblyCompanyAttribute
ascompany = Attribute.GetCustomAttribute(code, GetType(System.Reflection.AssemblyCompanyAttribute))
company = ascompany.Company
End If

If (Attribute.IsDefined(code, GetType(System.Reflection.AssemblyTitleAttribute))) Then
Dim asdescription As System.Reflection.AssemblyTitleAttribute
asdescription = Attribute.GetCustomAttribute(code, GetType(System.Reflection.AssemblyTitleAttribute))
description = asdescription.Title

End If

If (company <> String.Empty And description <> String.Empty) Then
Dim desktopPath As String = String.Empty
desktopPath = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "\", description, ".appref-ms")

Dim shortcutName As String = String.Empty
shortcutName = String.Concat(Environment.GetFolderPath(Environment.SpecialFolder.Programs), "\", company, "\", description, ".appref-ms")

System.IO.File.Copy(shortcutName, desktopPath, True)
End If

End If

End Sub
Left by Brandon on Jan 04, 2008 3:25 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Thanks a lot for your code.....It helps me a lot..

btw, two links in your post are dead..
Left by Michael Sync on May 19, 2008 9:54 AM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Two questions if I may

1) Won't the IsFirstRun test be true every time the application is updated via clickonce, since each update is a new versioned app.

2) Since click once is placed in a version referenced folder then every time you update the app a new icon will apear on the desctiop pointing to this new folder.

Are the above correct or am I missing the point.
Left by Andy on Jun 02, 2008 11:25 AM

# You need to add two references
Requesting Gravatar...
For the lazy and the newbies out there don't forget to add references to the appropriate namespaces:
using System.Deployment.Application;
using System.Reflection;
Left by Jerry Odom on Jun 05, 2008 3:39 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
You must also check if ApplicationDeployment.IsNetworkDeployed is true before running this code. If the application is distributed any other way than ClickOnce this code will fail.
Left by Christian on Oct 15, 2008 3:15 AM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Am I missing something? There's a checkbox on the Publish tab -> Options -> Manifest that, if checked, will cause a desktop shortcut to be created.

Left by Jack M on Jan 13, 2009 11:54 AM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Please do not publish redundant code


Publish tab -> Options -> Manifest does the trick.
Left by newbie on Jan 27, 2009 12:54 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
I don't have a Publish tab->Options->Manifest using VS2008 on project designer. What check-box is it and where specifically?
Left by cmac on Jan 28, 2009 1:16 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Same here...no Publish tab->Options->Manifest - VS 2005 SP1
Left by azmrtwo on Feb 05, 2009 6:30 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Create Shortcut option appears from VS2008 SP1
Left by Boz on Feb 16, 2009 3:40 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
My "create desktop shortcut" is greyed out under Publish > Options > Mainfests *ACK* I am just trying to run some command arguments to my application, and can't seem to make an editable shortcut to the darn thing!

Help?

Thanks!

Cry
Left by Cry on Feb 21, 2009 4:52 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Well.... discovered that the CREATE DESKTOP SHORTCUT is greyed out because the project isn't (wasn't) set to compile in .NET 3.5 (which you can change by going to the project properties page under compile - advanced options)

However, I still can't seem to put any arguments into the shortcut because it is part of a click once assembly rather then a normal application.

The battle continues.

Cry
Left by Cry on Feb 21, 2009 6:29 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
I've posted some information on how to get the desktop shortcut option into your application manifest:

http://devgems.blogspot.com/2009/03/clickonce-createdesktopshortcut-option.html
Left by Chris White on Mar 01, 2009 10:52 AM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Thanks for the code!
Left by Nigel Stratton on Mar 12, 2009 4:48 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
I do not see any place in VS 2008 to set the ability to create a desktop shortcut for ClickOnce. I have Target Framework set to .NET Framework 3.5. Where do I find the checkbox?
Left by David Simmonds on Mar 19, 2009 1:17 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
I've implemented this code and am now running into a different issue with it. When a user has version 1 of my application and updates to version 2 via ClickOnce, the shortcut is created properly but if the user had moved the icon to a preferred position on their desktop the icon has moved. Do you know of any way that the position of the shortcut on the desktop can be controlled in code?

Any help would be appreciated. Thanks for the great work around!
Left by Katie on Apr 06, 2009 1:48 PM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
David,
Make sure you are using Visual Studio 2008 *SP1* That was my problem.

Katie,
As far as I know (and feel free someone to correct me), that type of information is kept within the registry... you would need to parse that information. I came up with the following places, but have not confirmed it myself:

•HKEY_CURRENT_USER\Software\Microsoft\Windows\ShellNoRoam
•HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell
•HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell (Only in Windows Vista)
Left by DevilBoy on May 06, 2009 9:42 AM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Thanks for posting this for those of us who are still using 2.0 Framework.
Left by rsyed on May 14, 2009 11:35 AM

# Here is where to find the PUBLISH tab!
Requesting Gravatar...
Right-click on your solution in the Solution explorer. Go to Properties.

You will find a PUBLISH tab on that page.

Click on OPTIONS followed by MANIFEST and you will find the Create Desktop Shortcut there.

And for this guy: 1/27/2009 12:54 PM newbie who asked the author to "not publish redundant code", you should pay more attention to the date of the post! It was in 2007!
Left by Beltshumeltz on Jun 21, 2009 5:53 AM

# Here is where to find the PUBLISH tab!
Requesting Gravatar...
or even worse, it was from 2006 actually.
Left by Beltshumeltz on Jun 21, 2009 5:54 AM

# re: How to add Desktop Shortcut to ClickOnce Deployment Application
Requesting Gravatar...
Chris White - thanks for external link. Was really helpful.
Left by Grzegorz on Oct 07, 2010 3:26 AM

Your comment:
 (will show your gravatar)


Copyright © Murray Gordon | Powered by: GeeksWithBlogs.net