Click here to Skip to main content
13,299,898 members (68,819 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


12 bookmarked
Posted 6 Apr 2011

A simple update method in C#

, 3 Feb 2012
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)
                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

You may also be interested in...


Comments and Discussions

GeneralAlthough it isn't strictly an issue in C#, it's ill advised ... Pin
StephenPhillips6-Feb-12 13:51
memberStephenPhillips6-Feb-12 13:51 
GeneralTwo tips: 1. You should either use the webclient in a 'using... Pin
nbgangsta14-Apr-11 4:07
membernbgangsta14-Apr-11 4:07 
GeneralReason for my vote of 3 Very rough code, needs better loopin... Pin
Trellium13-Apr-11 18:46
memberTrellium13-Apr-11 18:46 
GeneralReason for my vote of 3 My biggest complain is that, in gene... Pin
ivanicin12-Apr-11 14:46
memberivanicin12-Apr-11 14:46 
GeneralReason for my vote of 3 Never have endless loop that do noth... Pin
Kim Togo11-Apr-11 23:22
memberKim Togo11-Apr-11 23:22 
GeneralReason for my vote of 3 1. Endless cycles? Brrrrr 2. Can you... Pin
InTRUEdeR7-Apr-11 15:32
memberInTRUEdeR7-Apr-11 15: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.

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