Click here to Skip to main content
15,887,596 members
Articles / Programming Languages / XML
Tip/Trick

Update Checker

Rate me:
Please Sign up or sign in to vote.
3.12/5 (10 votes)
25 Sep 2019CPOL 10.5K   551   6   6
Update Checker

Introduction

I was looking for a simple solution of a common problem: you have created an update of your application.

After you uploaded it to the server, you want that all the "old" applications (clients) get a message about this new version by checking for this automatically.

Background

My solution is very simple, the .NET DLL is small.

This XML file manages the updates (new Version 9.1.5 at https://leochapiro.de/data/TestApp.exe):

XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<myCoolApp>
    <currentVersion>
        <major>9</major>
        <minor>1</minor>
        <build>5</build>
    </currentVersion>
    <path>https://myCoolApp.zip</path>
</myCoolApp>

The main function Check4Update() reads the XML file and parses it:

C#
XmlDocument oDom = new XmlDocument();
oDom.Load(_sXmlConfig);

string str = oDom.SelectSingleNode("//currentVersion/major").InnerText;
Int32.TryParse(str, out _nMajor);

str = oDom.SelectSingleNode("//currentVersion/minor").InnerText;
Int32.TryParse(str, out _nMinor);

str = oDom.SelectSingleNode("//currentVersion/build").InnerText;
Int32.TryParse(str, out _nBuild); 

_sNewVersionPath = oDom.SelectSingleNode("//path").InnerText;

Using the Code

This solution is a .NET library (DLL) and can be used in every C# project by adding it as reference:

Then you only need to create an instance of it:

C#
axcsCheck4Update.axMain oCheckClient = new axcsCheck4Update.axMain(txtXml.Text);

int nMajor = oCheckClient.GetVersion(axcsCheck4Update.enVerion.EMajor);
int nMinor = oCheckClient.GetVersion(axcsCheck4Update.enVerion.EMinor);
int nBuild = oCheckClient.GetVersion(axcsCheck4Update.enVerion.EBuild);

string strPath = oCheckClient.GetNewVersionPath();

After getting the current version's number, you can compare it to your version's number:

C#
// Get my own version's numbers
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

int nAppMajor = fileVersionInfo.FileMajorPart;
int nAppMinor = fileVersionInfo.FileMinorPart;
int nAppBuild = fileVersionInfo.FileBuildPart;

And, if they are different, you can point users to this new version like this:

History

  • Version 1.0.0 released

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Germany Germany

I'm a software developer living in Germany with my family (wife & 2 sons).
My hobbies: sport, traveling, books (former reading, now hearing).
Welcome to my homepage: http://leochapiro.de

Comments and Discussions

 
QuestionNo result from "new axcsCheck4Update.axMain" Pin
Hanibani423-Jul-21 6:34
Hanibani423-Jul-21 6:34 
AnswerRe: No result from "new axcsCheck4Update.axMain" Pin
Leo Chapiro15-Sep-21 23:06
professionalLeo Chapiro15-Sep-21 23:06 
Questionlink is broken, and ... Pin
BillWoodruff29-Sep-19 22:08
professionalBillWoodruff29-Sep-19 22:08 
AnswerRe: link is broken, and ... Pin
Leo Chapiro1-Oct-19 4:23
professionalLeo Chapiro1-Oct-19 4:23 
QuestionVery Handy Pin
  Forogar  26-Sep-19 3:22
professional  Forogar  26-Sep-19 3:22 
AnswerRe: Very Handy Pin
Leo Chapiro26-Sep-19 23:40
professionalLeo Chapiro26-Sep-19 23:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.