65.9K
CodeProject is changing. Read more.
Home

Dynamically Check for Updates

starIconstarIconemptyStarIconemptyStarIconemptyStarIcon

2.00/5 (6 votes)

Jan 9, 2008

GPL3
viewsIcon

30880

downloadIcon

289

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