Fierce Waffle
Enthusiast
In this tutorial I will be showing you how to make your programming check for updates by checking an xml website. I recommend 110mb.com for free hosting.
First of all make sure you have
at the top.
Now create a new button and double click it to make a new event handler. This is the button we will be using to check for updates.
Now what that code is doing is its checking an XML file on your file server.
Here is what the Xml file should be formatted like
the about section of the XML tells the user about whats in the new update. version shows the new version. The code compares that versus the assembly version of you application. Feel free to ask any other Q's.
First of all make sure you have
Code:
using System.Xml
Now create a new button and double click it to make a new event handler. This is the button we will be using to check for updates.
Code:
private void updButton_Click_1(object sender, EventArgs e)
{
string downloadUrl = "";
Version newVersion = null;
string aboutUpdate = "";
string xmlUrl = "http://www.fiercemodder.com/Fierce%20Modder/update.xml";
XmlTextReader reader = null;
try
{
reader = new XmlTextReader(xmlUrl);
reader.MoveToContent();
string elementName = "";
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "appinfo"))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
elementName = reader.Name;
}
else
{
if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
switch (elementName)
{
case "version":
newVersion = new Version(reader.Value);
break;
case "url":
downloadUrl = reader.Value;
break;
case "about":
aboutUpdate = reader.Value;
break;
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Environment.Exit(1);
}
finally
{
if (reader != null)
reader.Close();
}
Version applicationVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
if (applicationVersion.CompareTo(newVersion) < 0)
{
string str = String.Format("New version found!\nYour version: {0}.\nNewest version: {1}. \nAdded in this version: {2}. ", applicationVersion, newVersion, aboutUpdate);
if (DialogResult.No != MessageBoxEx.Show(str + "\nWould you like to download this update?", "Check for updates", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
try
{
Process.Start(downloadUrl);
}
catch { }
return;
}
else
{
;
}
}
else
{
MessageBoxEx.Show("Your version: " + applicationVersion + " is up to date.", "Check for Updates", MessageBoxButtons.OK, MessageBoxIcon.None);
}
}
Now what that code is doing is its checking an XML file on your file server.
Here is what the Xml file should be formatted like
Code:
<?xml version="1.0" encoding="utf-8" ?>
<appinfo>
<version>1.5.0.0</version>
<url>http://www.fiercemodder.com/Fierce%20Modder/v1.5.rar</url>
<about>Remapped UI. Get License file from me</about>
</appinfo>
the about section of the XML tells the user about whats in the new update. version shows the new version. The code compares that versus the assembly version of you application. Feel free to ask any other Q's.