Post: [C#] Auto Updater - Tutorial
09-25-2015, 02:35 AM #1
Hash847
Purple God
(adsbygoogle = window.adsbygoogle || []).push({}); I've seen in the programming inquery section that there's a few people wanting an auto updater for their tools and stuff.


What you need
  • A direct download file host (dropbox)
  • A pastebin account
  • C#
  • a brain


We'll need a file host. I would personally suggest dropbox for this and that's what we'll be using for this tutorial.

After you've assumingly downloaded and installed dropbox + made an account, you can go to C:\Users\YOURUSERNAME\Dropbox and copy your updated file in there.

right click on it and press Shark Dropbox link. Keep it in your clipboard, we're now going to create a .txt in that same directory (if you're not using dropbox then use pastebin, make sure you use an account when you paste it because you'll need to edit the link)

on the first line put your latest version number
paste the link on the second line at the end of the link change dl=0 to dl=1, this is crucial to the dropbox download.
if you're using pastebin make sure you get the raw link

now with all that out of the way, we can begin adding our auto updater in.

    
int thisVersion = 1;
void checkForUpdates() {
string[] lns = new System.Net.WebClient().DownloadString("TXT FILE LINK OR DROPBOX LINK THAT ENDS IN DL=1").Split('\n'Winky Winky;
if (int.Parse(lns[0]) > thisVersion) {
new System.Net.WebClient().DownloadFile(lns[1], Application.ExecutablePath.Insert(Application.ExecutablePath.Length - 4, " " + thisVersion.ToString())); //this isn't async so it'll pause the thread
System.Diagnostics.Process.Start(Application.ExecutablePath.Insert(Application.ExecutablePath.Length - 4, " " + thisVersion.ToString()));
Application.Exit();//I know it's not pretty but I'm doing this on a website so clearly it wont be pretty
}
}


So at the end you should have a txt file that looks a bit like this
    
1
https://www.dropbox.com/s/gawykghypvbnda5/whatyoucalledit.txt?dl=1


If you want to update your application just edit the .txt and change 1 to 2 and so on and make sure in your updated version you change thisVersion to whatever the latest version is. (it can't be like 1.1 it has to be a whole number like 2 and 3)
I hope this helps anyone that requires it.

The following user thanked Hash847 for this useful post:

RTE
10-01-2015, 07:25 PM #11
LBK
Little One
If you just need a auto-update , with no ProgressBar and other , why no just code this :
    
string str = "1.0";
string str2 = new WebClient().DownloadString("YourLinkWithUpdateNumber2.0.txt"); // Just write 2.0 on your txt
if (str2 == str)
{
MessageBox.Show("No Update on this tool ");
}
else
{
MessageBox.Show("Errorr ! New Update For this tool , Dowlod here : http.YourLinkForUpdate");

}

Yeah i agree ith you , my code , no use proCessTstart for directly dowloand Update , but code is very easy Smile

Very nice post good Job Smile Keep it up !
10-02-2015, 08:34 AM #12
Hash847
Purple God
Originally posted by LBK View Post
If you just need a auto-update , with no ProgressBar and other , why no just code this :
    
string str = "1.0";
string str2 = new WebClient().DownloadString("YourLinkWithUpdateNumber2.0.txt"); // Just write 2.0 on your txt
if (str2 == str)
{
MessageBox.Show("No Update on this tool ");
}
else
{
MessageBox.Show("Errorr ! New Update For this tool , Dowlod here : http.YourLinkForUpdate");

}

Yeah i agree ith you , my code , no use proCessTstart for directly dowloand Update , but code is very easy Smile

Very nice post good Job Smile Keep it up !


the point of this is to make it simple and compact, so you can actually update without needing a static download link. Also the process.start is to launch the new update

Copyright © 2025, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo