Post: [C#] Need Help With Update Button
06-30-2013, 06:30 PM #1
MrSpliiffy
Bounty hunter
(adsbygoogle = window.adsbygoogle || []).push({}); i Need Help
Does Anyone Know How to add a Update Button to a application C'Sharp ?
Saves Me To keep Posting Same Application Over and over if You Can Help Add My Skype mrspliiffymodz

Cheers Smile
Last edited by MrSpliiffy ; 06-30-2013 at 06:32 PM.
06-30-2013, 06:52 PM #2
Pichu
RIP PICHU.
Originally posted by MrSpliiffy View Post
i Need Help
Does Anyone Know How to add a Update Button to a application C'Sharp ?
Saves Me To keep Posting Same Application Over and over if You Can Help Add My Skype mrspliiffymodz

Cheers Smile


By update button are you meaning to check to see whether or not there is a new version available? If so, you will need hosting, 000webHost will work.

From there, I'll inform you on what you need. I was actually looking to make this my next tutorial in C# for my website. I might just write it up today for you.
06-30-2013, 07:43 PM #3
MrSpliiffy
Bounty hunter
Ohh Thanks Man Give Me Your Website i Love to Check it out and could you add Me On Skype mrspliiffymodz So you can go bit more in-depth ?
Originally posted by Pichu View Post
By update button are you meaning to check to see whether or not there is a new version available? If so, you will need hosting, 000webHost will work.

From there, I'll inform you on what you need. I was actually looking to make this my next tutorial in C# for my website. I might just write it up today for you.
06-30-2013, 07:52 PM #4
Pichu
RIP PICHU.
Originally posted by MrSpliiffy View Post
Ohh Thanks Man Give Me Your Website i Love to Check it out and could you add Me On Skype mrspliiffymodz So you can go bit more in-depth ?


You must login or register to view this content.

I heavily commented the source code. You can basically add a button and add the source code and change a few things. You will need to create an XML file as well as use a web host, you can use free ones.

The following user thanked Pichu for this useful post:

MW2TopTenWORLD
07-02-2013, 06:55 PM #5
Master Ro
I make food
Originally posted by MrSpliiffy View Post
i Need Help
Does Anyone Know How to add a Update Button to a application C'Sharp ?
Saves Me To keep Posting Same Application Over and over if You Can Help Add My Skype mrspliiffymodz

Cheers Smile


If you have web hosting, this is extremely easy.

A simple way to do it would be to create a directory in FTP containing a text file, and a string called 'Version' in your program.

On the first line of the text file, include the target version, and on the second line, include the download link.

read the content from the URL and check if the first line of your content matches your 'Version' variable. If it does, don't update. If it doesn't, send the user to the download link on the second line.

Code example:

    
WebClient client = new WebClient();
Stream stream = client.OpenRead(<URL>Winky Winky;
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();


string[] vals = content.Split('\n'Winky Winky;


//vals[0] = version
//vals[1] = download link


if (vals[0] == BotInfo.Bot_Version)
{
System.Windows.Forms.MessageBox.Show("No new updates", "Check for Updates", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
return;
}


if (vals[0] != BotInfo.Bot_Version)
{
System.Windows.Forms.MessageBox.Show("New Update found! Version: " + vals[0], "Update Found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
System.Diagnostics.Process.Start(vals[1]);
}
07-02-2013, 08:31 PM #6
Pichu
RIP PICHU.
Originally posted by Everybody
If you have web hosting, this is extremely easy.

A simple way to do it would be to create a directory in FTP containing a text file, and a string called 'Version' in your program.

On the first line of the text file, include the target version, and on the second line, include the download link.

read the content from the URL and check if the first line of your content matches your 'Version' variable. If it does, don't update. If it doesn't, send the user to the download link on the second line.

Code example:

    
WebClient client = new WebClient();
Stream stream = client.OpenRead(<URL>Winky Winky;
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();


string[] vals = content.Split('\n'Winky Winky;


//vals[0] = version
//vals[1] = download link


if (vals[0] == BotInfo.Bot_Version)
{
System.Windows.Forms.MessageBox.Show("No new updates", "Check for Updates", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
return;
}


if (vals[0] != BotInfo.Bot_Version)
{
System.Windows.Forms.MessageBox.Show("New Update found! Version: " + vals[0], "Update Found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
System.Diagnostics.Process.Start(vals[1]);
}


Did mine using an XML file although I noticed a small bug; I've gotta tweak it to where it can accept multiple elements in the XML file so you can use a single update file rather than having to direct towards a specific XML file.

Still, it works.
07-19-2013, 02:21 PM #7
Originally posted by Pichu View Post
You must login or register to view this content.

I heavily commented the source code. You can basically add a button and add the source code and change a few things. You will need to create an XML file as well as use a web host, you can use free ones.


Hey!
Ive based on your Code and Ive added something.

    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Diagnostics;
using System.Net;

namespace Programming_NotePad
{
public partial class MainPage : DevComponents.DotNetBar.Metro.MetroForm
{
public MainPage()
{
InitializeComponent();
}

private void MainPage_Load(object sender, EventArgs e)
{
DialogResult dialog = MessageBox.Show("Hey would you like to check for updates now?", "Check for Updates", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dialog == DialogResult.Yes)
{
//Start update process
String downloadURL = "https://updateshost.webuda.com/Multi_Tool_Updates/File.exe";

Version newVersion = null;

String xmlUrl = "https://updateshost.webuda.com/Multi_Tool_Updates/Verify.xml";

XmlTextReader xmlReader = null;
try
{

xmlReader = new XmlTextReader(xmlUrl);

xmlReader.MoveToContent();

String elementName = "";

if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "updateTool"))
{

while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element)
{

elementName = xmlReader.Name;
}
else
{
if ((xmlReader.NodeType == XmlNodeType.Text) && (xmlReader.HasValue))
{

switch (elementName)
{
case "version": newVersion = new Version(xmlReader.Value);
break;
case "url": downloadURL = xmlReader.Value;
break;
default: MessageBox.Show("version or url not found!", "Error");
break;
}
}
}
}
}
}
catch (Exception ex)
{

MessageBox.Show(ex.ToString());
}

finally
{

if (xmlReader != null)
xmlReader.Close();
}
Version appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
if (appVersion.CompareTo(newVersion) < 0)
{

DialogResult downloadRequest = MessageBox.Show(String.Format("Version {0}.{1}.{2} is now available to download.\n\nWould you like to download?", newVersion.Major, newVersion.Minor, newVersion.Build), "Update Avaialable",
MessageBoxButtons.YesNo, MessageBoxIcon.Information);

if (downloadRequest == DialogResult.Yes)
{

SaveFileDialog download = new SaveFileDialog();
download.Title = "Choose where to save the new File";
download.Filter = "Exe Files | *.exe";
if (download.ShowDialog() == DialogResult.OK)
{
WebClient download2 = new WebClient();
download2.DownloadFile(downloadURL, download.FileName);
MessageBox.Show("Download Finished! , Application now quitting so you can install your new file");
Application.Exit();
}
else
{
//do nothing
}
}
}
else
{

MessageBox.Show("This application is currently up to date!", "Update", MessageBoxButtons.OK, MessageBoxIcon.None);
}



}
else if (dialog == DialogResult.No)
{
//Cancel Dialog
}
}



Its just something simple :P

The following user thanked MW2TopTenWORLD for this useful post:

Pichu
07-19-2013, 03:06 PM #8
Pichu
RIP PICHU.
Originally posted by MW2TopTenWORLD View Post
Hey!
Ive based on your Code and Ive added something.

    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Diagnostics;
using System.Net;

namespace Programming_NotePad
{
public partial class MainPage : DevComponents.DotNetBar.Metro.MetroForm
{
public MainPage()
{
InitializeComponent();
}

private void MainPage_Load(object sender, EventArgs e)
{
DialogResult dialog = MessageBox.Show("Hey would you like to check for updates now?", "Check for Updates", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (dialog == DialogResult.Yes)
{
//Start update process
String downloadURL = "https://updateshost.webuda.com/Multi_Tool_Updates/File.exe";

Version newVersion = null;

String xmlUrl = "https://updateshost.webuda.com/Multi_Tool_Updates/Verify.xml";

XmlTextReader xmlReader = null;
try
{

xmlReader = new XmlTextReader(xmlUrl);

xmlReader.MoveToContent();

String elementName = "";

if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "updateTool"))
{

while (xmlReader.Read())
{
if (xmlReader.NodeType == XmlNodeType.Element)
{

elementName = xmlReader.Name;
}
else
{
if ((xmlReader.NodeType == XmlNodeType.Text) && (xmlReader.HasValue))
{

switch (elementName)
{
case "version": newVersion = new Version(xmlReader.Value);
break;
case "url": downloadURL = xmlReader.Value;
break;
default: MessageBox.Show("version or url not found!", "Error");
break;
}
}
}
}
}
}
catch (Exception ex)
{

MessageBox.Show(ex.ToString());
}

finally
{

if (xmlReader != null)
xmlReader.Close();
}
Version appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
if (appVersion.CompareTo(newVersion) < 0)
{

DialogResult downloadRequest = MessageBox.Show(String.Format("Version {0}.{1}.{2} is now available to download.\n\nWould you like to download?", newVersion.Major, newVersion.Minor, newVersion.Build), "Update Avaialable",
MessageBoxButtons.YesNo, MessageBoxIcon.Information);

if (downloadRequest == DialogResult.Yes)
{

SaveFileDialog download = new SaveFileDialog();
download.Title = "Choose where to save the new File";
download.Filter = "Exe Files | *.exe";
if (download.ShowDialog() == DialogResult.OK)
{
WebClient download2 = new WebClient();
download2.DownloadFile(downloadURL, download.FileName);
MessageBox.Show("Download Finished! , Application now quitting so you can install your new file");
Application.Exit();
}
else
{
//do nothing
}
}
}
else
{

MessageBox.Show("This application is currently up to date!", "Update", MessageBoxButtons.OK, MessageBoxIcon.None);
}



}
else if (dialog == DialogResult.No)
{
//Cancel Dialog
}
}



Its just something simple :P


You've taken it and made it appear at load, you can do that though it's not needed. I also see you added the ability to download the file, that's something good there; though it wasn't what was asked aha. :P

Also, you don't need to include else statements and //do nothing or dialog == dialogResult.No {Cancel Dialog} since it does nothing regardless due to the bool values not resulting in true.

The following user thanked Pichu for this useful post:

MW2TopTenWORLD
07-19-2013, 04:15 PM #9
Originally posted by Pichu View Post
You've taken it and made it appear at load, you can do that though it's not needed. I also see you added the ability to download the file, that's something good there; though it wasn't what was asked aha. :P

Also, you don't need to include else statements and //do nothing or dialog == dialogResult.No {Cancel Dialog} since it does nothing regardless due to the bool values not resulting in true.


Yh I know but I always do Is something that I got used to :P, and I wasnt talking about putting it on Form_Load I was talking about the SaveFileDialog because it comes handy :P and the Download Function hehe.
Il be giving credit to you I only minimally Upgraded it Happy
07-19-2013, 04:50 PM #10
Pichu
RIP PICHU.
Originally posted by MW2TopTenWORLD View Post
Yh I know but I always do Is something that I got used to :P, and I wasnt talking about putting it on Form_Load I was talking about the SaveFileDialog because it comes handy :P and the Download Function hehe.
Il be giving credit to you I only minimally Upgraded it Happy


No credit needed. I just put the stuff out there to help others. When I was learning C# I didn't really have much tutorials, snippets, etc to work off of so I had to go about the hard way.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo