Post: Basic Updater For Your Program C#
07-13-2014, 04:58 AM #1
jagex
Gym leader
(adsbygoogle = window.adsbygoogle || []).push({}); Requirements:
(I will assume you are using dropbox)

1. Create 2 text files
2. Name on VersionNumber and inside it put your program version ex(1.0.0.1)
3. The second text file name is Downloadlink and insert the download link for your updated program

    
using System.Windows.Forms;
using System.Net;
using System.IO.Compression;


    
WebClient myWebclient = new WebClient();
string Temp;
string checkversion;


Add this code to where you want to start the update from
    
myWebclient.DownloadFileCompleted += OnDownloadComplete;
myWebclient.DownloadFileAsync(new Uri("URL for Version Number txt file goes here"), Temp + "VersionNumber.txt");




    
private void OnDownloadComplete(object sender, AsyncCompletedEventArgs e)
{
myWebclient.Dispose();
var reader = new System.IO.StreamReader(Temp + "VersionNumber.txt");
checkversion = reader.ReadToEnd();
reader.Dispose();
DownloadNewVersion();
}


    
private void DownloadNewVersion()
{
if (checkversion.Contains(Application.ProductVersion) )
{
MessageBox.Show("You have the latest version!", "Updater", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}
else
{


MessageBox.Show("Update Found!" + "\n" + "Current Version:" + " " + Application.ProductVersion + "\n" +
"New Version:" + " " + checkversion, "Updater", MessageBoxButtons.OK, MessageBoxIcon.Information);
myWebclient.DownloadFile("URL for Downloadlink txt file goes here", Temp + "Downloadlink.txt");
var Downloadlink = new System.IO.StreamReader(Temp + "Downloadlink.txt");
string Link = Downloadlink.ReadToEnd();
Downloadlink.Dispose();
FolderBrowserDialog SelectFolder = new FolderBrowserDialog();
SelectFolder.ShowDialog();
string Location = SelectFolder.SelectedPath;
if (Location == "")
{
MessageBox.Show("No Directory Selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;

}
else
{

try {
MessageBox.Show("Update Found!" + "\n" + "Current Version:" + " " + Application.ProductVersion + "\n" +
"New Version:" + " " + checkversion, "Updater", MessageBoxButtons.OK, MessageBoxIcon.Information);
myWebclient.DownloadFile("https://dl.dropbox.com/s/30pbkeg3nfr662y/NewVersion.txt?dl=1", Temp + "Downloadlink.txt");
var Downloadlink = new System.IO.StreamReader(Temp + "Downloadlink.txt");
string Link = Downloadlink.ReadToEnd();
Downloadlink.Dispose();
FolderBrowserDialog SelectFolder = new FolderBrowserDialog();
SelectFolder.ShowDialog();
string Location = SelectFolder.SelectedPath;
if (Location == "")
{
MessageBox.Show("No Directory Selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);


}
else
{

System.IO.Directory.CreateDirectory(Location + @"\NewVersion");
myWebclient.DownloadFile(Link, Location + @"\NewVersion\Update.zip");
myWebclient.Dispose();
string path = Location;
Location = "";
string zipPath = path + @"\NewVersion\Update.zip";
string extractPath = path + @"\NewVersion";
ZipFile.ExtractToDirectory(zipPath, extractPath);
System.IO.File.Delete(path + @"\NewVersion\Update.zip");
MessageBox.Show("Download Complete!" + "\n" + "Download Destination:" + " " + path, "Updater", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
System.Diagnostics.Process.Start(path);
/*Application.Exit()*/
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

}
}




Last edited by jagex ; 08-26-2014 at 05:26 PM.

The following 5 users say thank you to jagex for this useful post:

04jberry, Cyb3r, QuantumDev, ResistTheSteam, xKrazy SicknesS
07-16-2014, 02:35 AM #2
Cyb3r
NextGenUpdate Elite
Thanks you mate, it could get in handy later, keep up.
07-16-2014, 08:29 PM #3
jagex
Gym leader
No problem and thanks!
07-17-2014, 12:56 AM #4
jagex
Gym leader
Removed
Last edited by jagex ; 08-26-2014 at 02:25 AM.
07-26-2014, 02:57 PM #5
hotfix
Keeper
Here's another way. (Sorry for poor programming, I'm at work).

    
public static double localVersion = 1.0;
void update_app()
{
try
{
System.Net.WebClient client = new System.Net.WebClient();
System.IO.Stream stream = client.OpenRead("https://www.website.com/fileversion.txt");
System.IO.StreamReader reader = new System.IO.StreamReader(stream);
double liveVersion = Convert.ToDouble(reader.ReadToEnd());
DialogResult dialogResult = MessageBox.Show("Would you like to download the newest update?", "Update " + liveVersion.ToString() + " Available", MessageBoxButtons.YesNo);
if (liveVersion > localVersion)
if (dialogResult == DialogResult.Yes)
System.Diagnostics.Process.Start("https://www.website.com/file.zip");
else
MessageBox.Show("You are running: " + localVersion.ToString() + "\nThis is the current version.");
stream.Close();
stream.Dispose();
client.Dispose();
}
catch
{
MessageBox.Show("Cannot Update. Check your connection.");
}
}

The following user thanked hotfix for this useful post:

Pichu
07-29-2014, 05:33 PM #6
Joshua.avacado
Do a barrel roll!
wait wait. what does this exactly do?
07-29-2014, 06:10 PM #7
jagex
Gym leader
Originally posted by Joshua.avacado View Post
wait wait. what does this exactly do?



Downloads update for your program lol...
07-29-2014, 07:07 PM #8
Joshua.avacado
Do a barrel roll!
so i can sent updates? skype me im so confused idk if im just derping right now. joshua.avacado <-- skype
07-30-2014, 03:24 PM #9
jagex
Gym leader
Its for people using your program

if you make a new version you put the download link the in the textfile, change the version in the other textfile and the user clicks update on the program and it will download the new one for them
Last edited by jagex ; 08-24-2014 at 04:25 PM.
08-18-2014, 02:27 AM #10
QuantumDev
Can’t trickshot me!
Not bad. Keep it up Happy

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo