Click here to Skip to main content
Licence GPL3
First Posted 9 Jan 2008
Views 13,767
Downloads 129
Bookmarked 18 times

Dynamically Check for Updates

By | 9 Jan 2008 | Article
How to check for updates

Introduction

This simple code checks for updates. The solution contains a window application and a class library. The main functionality lies in the class library while the window application contains user interface logic. You can tell the user that a new update is available for download etc.

Using the Code

In your class library project, for example, you have a method getName() that returns the name of the user in lower case.

public function string getName(string name)
{
    return name.ToLower();
}

Later on, it changed from name.ToUpper() in your class library, but the end user has the old code. So the following code in your window application checks for updates:

private void checkForUpdateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Get current executing assembly version
            TestAssembly.Class1 myClass = new TestAssembly.Class1();
            Type type = myClass.GetType();
            Assembly assembly = Assembly.GetAssembly(type);
            MessageBox.Show(assembly.GetName().Version.ToString() + " " + 
                    assembly.GetName());

            //Get the remote assembly.
            Assembly objAssembly = null;
            objAssembly = Assembly.LoadFrom("http://www/homes/adeel/TestAssembly.dll");
            MessageBox.Show(objAssembly.GetName().Version.ToString()+ " "+
                    objAssembly.GetName());

            //Compare the versions. You should compare the revisions too.
            if (objAssembly.GetName().Version.Major > assembly.GetName().Version.Major)
            {
                MessageBox.Show("An update is available.");
            }
            else if (objAssembly.GetName().Version.Major < 
                    assembly.GetName().Version.Major)
            {
                MessageBox.Show("You have the latest version.");
            }
        }

History

  • 9th January, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

Adeel Hussain

Web Developer
Allainet (Pvt) Ltd
Pakistan Pakistan

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmvpSimon Stevens1:44 18 Mar '09  
QuestionCould you please exchange loading assembly to loading of xml? PinmemberCuchuk Sergey21:17 6 Mar '08  
AnswerRe: Could you please exchange loading assembly to loading of xml? PinmemberAdeel Hussain1:29 10 Mar '08  
yes it is better to user xml instead of loading assembly. You can use HttpWebRequest and XmlDocument classes. Sample code looks like:
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(string.Format("http://xml file url");
WebReq.Method = "GET";
WebReq.AllowAutoRedirect = true;
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream Answer = WebResp.GetResponseStream();
StreamReader _Answer = new StreamReader(Answer);
string response = _Answer.ReadToEnd();
 
XmlDocument objDoc= new XmlDocument();
objDoc.InnerXml = response;//It must be xml
 
XmlElement rootElement = objDoc.DocumentElement;
XmlNodeList objNodeList = objDoc.SelectNodes("/assemblyname/version");
string latestVersion="";
if (objNodeList.Count != 0)
{
latestVersion = nodeList[0].Attributes["latestVersion"].InnerText;
}
//Parse the latestVersion variable. and compare to current version.
 
Adeel Hussain

GeneralRe: Could you please exchange loading assembly to loading of xml? PinmemberCuchuk Sergey20:15 10 Mar '08  
GeneralCouple of points... PinmemberRay Hayes3:16 9 Jan '08  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 9 Jan 2008
Article Copyright 2008 by Adeel Hussain
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid