Writing ClickOnce Applications

There are times when you write a Windows desktop application that needs to be run on a large number of client machines, could be updated at any time, and needs a connection back to a web server. The Windows .NET 2.0 framework introduced the concept of ClickOnce to deploy desktop applications through a link on a web site (see MSDN Article.)

It is relatively easy to create a .NET ClickOnce package out of any normal Windows application written in a .NET language such as VB or C#. First, indicate in the project properties that you want to sign the ClickOnce manifests (signing the assembly is not required.) Also enable ClickOnce Security Settings. Finally, you can publish the application as a ClickOnce package to a web site or file path.

Each time the user clicks on a link pointing to MyApp.application from the web site, the ClickOnce package is downloaded if a newer version exists than the one in the local users ClickOnce cache. Obviously, Internet Explorer can run ClickOnce applications on machines with the .NET 2.0 framework installed, but Firefox can also run it with the FFClickOnce add-on.

Here are a few hints on making a useful client application. Let's say that the web site that launches the ClickOnce application also provides web services to provide back-end business logic and data. You could extract URL path and query information used in launching the ClickOnce application as shown below:

string query = System.Deployment.Application.ApplicationDeployment.
    CurrentDeployment.ActivationUri.Query;
string serverURL = System.Deployment.Application.ApplicationDeployment.
    CurrentDeployment.ActivationUri.ToString();
int pos = serverURL.ToLower().LastIndexOf("/");
if (pos > 0)
    serverURL = serverURL.Substring(0, pos);

Web service calls can now be established as either simple HTTP requests or more dynamic protocols such as SOAP or REST.