How To Check for Program updates in C#

Part 1 :

Hi, have a good day.

This simple class will help to check for your application updates, and it’s very simple.

First create a text file on your website “myapp-pro.txt” for example:
and add the following content to it :

MyAppPro;2.0;http://www.smart-arab.com/MyAppPro-2.0.zip

Notice that each properties is  separated with “;”.

C# Class :

    class CheckUpdates
    {
        public string appname = string.Empty;
        public Version version = new Version();
        public string newdownloadlink = string.Empty;

        public CheckUpdates(string uri)
        {
            WebClient client = new WebClient();
            string content = string.Empty;
            Stream stream;

            try
            {
                stream = client.OpenRead(uri);
                StreamReader reader = new StreamReader(stream);
                content = reader.ReadToEnd();
            }
            catch (WebException ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            string[] strContent = content.Split(';');
            if (strContent.Length != 3)
            {
                MessageBox.Show("text file must be in this format \"appname;version;newurl\"");
                return;
            }

            appname = strContent[0];
            version = new Version(strContent[1]);
            newdownloadlink = strContent[2];
        }
    }

Usage Example :

 CheckUpdates checkupdate = new CheckUpdates("http://www.smart-arab.com/updates/myapp-pro.txt");
            MessageBox.Show(checkupdate.appname + "\r\n" + checkupdate.version.ToString() + "\r\n" + checkupdate.newdownloadlink);

In the Next post I will show how to update your Application Automatically With C# :)

Comments

Leave a Reply

Your email address will not be published.