Click here to Skip to main content
Click here to Skip to main content

Tagged as

A simple update method in C#

, 3 Feb 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple update method in C#
This code is in version 1. I hope you understand my English and my code.
 
This code is very useful to update your application:
 
using System.Windows.Forms; //because MessageBox.Show();
using System.Net; //because WebClient
using System.IO; //because StreamReader
using System.Diagnostics; //because Process.Start
using System.Thread;
 
        static void update()
        {
	        StreamReader versionread;
	        Uri url = new Uri(/*insert your url to check if a new version is available here. It has to be an .txt file*/); //string
		Uri updateurl = new Uri(/*insert your url for the latest .exe version here*/); //string
		int intVers = 0;
            WebClient update = new WebClient();
            update.DownloadFileAsync(url,/*insert the name of the .txt file here*/); //string
            while (update.IsBusy)
            {
                Thread.Sleep(1);
            }
                versionread = new StreamReader(/*insert the name of the .txt file here*/); //string
                intVers = Convert.ToInt32(versionread.ReadLine());
 
            if (intVers > /*latest version*/)
            {
                update.DownloadFileAsync(updateurl, /*insert the name of the latest .exe version here*/); //string
                while (update.IsBusy)
                {
                    Thread.Sleep(1);
                }
 
                    MessageBox.Show("Update sucessfully");
                    //
					//installing process
					//
					Process.Start(/*insert the name of the latest .exe version here*/); //string
                    Close();
            }
            else
            {
                MessageBox.Show("No Version available");
            }

License

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

Share

About the Author

GoatMachine
Student
Germany Germany
No Biography provided

Comments and Discussions

 
GeneralAlthough it isn't strictly an issue in C#, it's ill advised ... PinmemberStephenPhillips6-Feb-12 13:51 
GeneralTwo tips: 1. You should either use the webclient in a 'using... Pinmembernbgangsta14-Apr-11 4:07 
GeneralReason for my vote of 3 Very rough code, needs better loopin... PinmemberTrellium13-Apr-11 18:46 
GeneralReason for my vote of 3 My biggest complain is that, in gene... Pinmemberivanicin12-Apr-11 14:46 
GeneralReason for my vote of 3 Never have endless loop that do noth... PinmemberKim Togo11-Apr-11 23:22 
GeneralReason for my vote of 3 1. Endless cycles? Brrrrr 2. Can you... PinmemberInTRUEdeR7-Apr-11 15:32 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.1411023.1 | Last Updated 3 Feb 2012
Article Copyright 2011 by GoatMachine
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid