Blog

C# Application that checks for new versions

Normally when I create some application and know that users will use it a lot, there is a underlying need of making sure the end user is using the latest version.

To show one way of making this possible is using xml files at the server side, describing the changes and where to fetch new versions.
So in other means, the code explain it self….

OrdinaryApp.zip Containing the source with example.


public static string VERSION = "0.5";

public Form1()
{
InitializeComponent();

// Register the Event to trigger a method when Updates are found.
eventCatcher();
}

private void eventCatcher()
{

CheckUpdate.NewVersionToDownloadEvent += new CheckUpdate.NewVersionToDownload(newVersion);
}

///
/// Get the new version available
///
///
private void newVersion(object newVersion)
{
NewVersion nV = (NewVersion)newVersion;
DialogResult dr =
MessageBox.Show(nV.MessageFromXml, "New version:" + nV.Version + " is available.",
MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
MessageBoxOptions.ServiceNotification);
if (dr == DialogResult.Yes)
{
Process.Start(nV.Url + nV.Filename);
}
}

///
/// The metod triggerd when the application has loaded.
///
///
///
private void onLoad(object sender, EventArgs e)
{
// This could be when started, or button or other thing.
new CheckUpdate(false, VERSION, "http://www.lightsoft.se/_software_updates/OrdinaryApp.xml");
}

Then the XML file describing the versions could look like this:


<!--<update currentversionnumber="0.7" downloadurl="http://www.lightsoft.se">-->
<update currentversionnumber="1.0" downloadurl="http://www.lightsoft.se/_software_updates/UpdateTestApp/" filename="OrdinaryApp.zip">
  <version versionnumber="1.1" versiondate="2008-09-01">
    <newfeature>Added autocheck if an update is possible</newfeature>
    <bugfix>Change the thread management for the text to be update. New rules in .Net 3.0</bugfix>
  </version>
  <version versionnumber="1.0" versiondate="2008-08-01">
    <performance>Faster calculations</performance>
  </version>
  <version versionnumber="0.1" versiondate="2004-01-01">
    <newfeature>Main application done</newfeature>
  </version>
  <version versionnumber="0.0.1" versiondate="2003-12-01">
    <newfeature>Beta 1</newfeature>
  </version>
</update>


Leave a Reply