Camera Icon

Got an event that needs shooting?  I've covered multiple events for marathon-photos.com and can capture the scenes & emotions that make your event unique.

Some samples of my own work are at Digital Formula on Flickr.

Wand Icon

Do you or your business need a website but you're unsure where to start?  Get in touch now and we'll get it sorted.

I focus on usable functionality & can setup smaller sites using Wordpress within hours of the order being placed.  Magic!

Globe Icon

So, you've already got a website but need help managing it?  I can help you.

Don't worry about knowing every single detail.  I'll find out the most important stuff and work with you to reach your goal, not someone else's.

said on twitter: LOL spammers really do bank on the ignorance of their targets huh? A file with a .jpg.exe extension ... really? http://t.co/0TgobjQc

 
Short URL
Warning: This article is older than 180 days and may contain inaccurate information.  Please use the information below at your own risk.

C# - Self updating application ...

... without ClickOnce!

Disclaimer: I wrote this code way back in 2007 and I reckon I've learnt a fair bit since then (not being a professional developer).  Go easy on me if you feel like commenting on the code itself.  :-)

This one might be interesting for people who have wondered about how to distribute the latest version of their application without having to tell people when an update is released.

There are built-in options that you can use with the Microsoft .NET platform such as ClickOnce. We use ClickOnce here at Trade Me to deploy some of our in-house applications and it works really well.

Recently, though, I thought "Why not see if I can write my own method of updating my application?" It turned out to be quite an interesting litte project! The application I was working on at the time is written in C# although the learning curve to go from VB.NET to C# or vice-versa isn't too steep.

Where do we start?

To begin with I decided the update process should have the following steps.

  • Check my website for a text file containing version information.
  • Read the version information text file and compare the version information in it to the version of the application currently running.
  • If the version in the text file is the same or less than the version currently being run, do nothing other than show a message to the user.
  • If the version in the text file is greater than the version currently being run ask the user if they want to update to the later version.
  • Do the actual update.

Components

There are 2 components to this particular solution. The first part is the actual application being updated and the updater application. If you are going to follow along with any of the stuff in this article you'll need to start a new solution with 2 projects. My main project is called "CountDown" and the updater application is called "AppStart" (for reasons not related to the updating stuff here). For the purposes of this article I'm going to assume you have a single project that needs the update functionality.

The main application

The first thing your main application will need to do is make use of the System.Net namespace by adding the following line to the top of the main namespace file.

using System.Net;

When the user runs the application they can click a button that runs a method to do most of the steps above. The first thing the method does is try to resolve the IP address of my website (http://www.digitalformula.net resolves to 203.194.159.161).

try
{
  string RemoteDomain = "http://www.digitalformula.net";
  IPHostEntry inetServer = Dns.GetHostEntry(RemoteDomain.Replace("http://", String.Empty));
}
catch (Exception ex)
{
...
}

1 2 3 4 5 Next »

» Tags: c#, clickonce, self-updating application
DigitalFormula is an experiment in HTML5 and CSS3 design by Chris Rasmussen, an amateur/casual designer based in Melbourne, Australia. -37.813611 144.963056