Click here to Skip to main content
15,888,454 members
Articles / Programming Languages / C#
Article

Dynamically Check for Updates

Rate me:
Please Sign up or sign in to vote.
2.00/5 (6 votes)
9 Jan 2008GPL3 30.5K   288   19   5
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.

C#
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:

C#
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)


Written By
Web Developer Allainet (Pvt) Ltd
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Simon P Stevens18-Mar-09 1:44
Simon P Stevens18-Mar-09 1:44 
QuestionCould you please exchange loading assembly to loading of xml? Pin
drweb866-Mar-08 21:17
drweb866-Mar-08 21:17 
AnswerRe: Could you please exchange loading assembly to loading of xml? Pin
Adeel Hussain10-Mar-08 1:29
Adeel Hussain10-Mar-08 1:29 
GeneralRe: Could you please exchange loading assembly to loading of xml? Pin
drweb8610-Mar-08 20:15
drweb8610-Mar-08 20:15 
GeneralCouple of points... Pin
Ray Hayes9-Jan-08 3:16
Ray Hayes9-Jan-08 3:16 

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.