Click here to Skip to main content
14,669,678 members
Articles » General Programming » Programming Tips » General
Posted 6 Apr 2011

Tagged as


13 bookmarked

A simple update method in C#

Rate this:
3.08 (11 votes)
Please Sign up or sign in to vote.
3.08 (11 votes)
3 Feb 2012CPOL
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)
                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)

                    MessageBox.Show("Update sucessfully");
					//installing process
					Process.Start(/*insert the name of the latest .exe version here*/); //string
                MessageBox.Show("No Version available");


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


About the Author

Germany Germany
No Biography provided

Comments and Discussions

GeneralAlthough it isn't strictly an issue in C#, it's ill advised ... Pin
StephenPhillips6-Feb-12 12:51
MemberStephenPhillips6-Feb-12 12:51 
GeneralTwo tips: 1. You should either use the webclient in a 'using... Pin
Groulien14-Apr-11 3:07
MemberGroulien14-Apr-11 3:07 
GeneralReason for my vote of 3 Very rough code, needs better loopin... Pin
Trellium13-Apr-11 17:46
MemberTrellium13-Apr-11 17:46 
GeneralReason for my vote of 3 My biggest complain is that, in gene... Pin
Ivan Ičin12-Apr-11 13:46
MemberIvan Ičin12-Apr-11 13:46 
GeneralReason for my vote of 3 Never have endless loop that do noth... Pin
Kim Togo11-Apr-11 22:22
professionalKim Togo11-Apr-11 22:22 
GeneralReason for my vote of 3 1. Endless cycles? Brrrrr 2. Can you... Pin
intrueder7-Apr-11 14:32
Memberintrueder7-Apr-11 14:32 

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.