HttpWebRequest web;
try
{
web = (HttpWebRequest)HttpWebRequest.Create("website.name");
WebResponse Response = web.GetResponse();
Stream WebStream = Response.GetResponseStream();
StreamReader Reader = new StreamReader(WebStream);
string data = Reader.ReadToEnd();
Reader.Close();
WebStream.Close();
Response.Close();
string[] ver = Regex.Split(data, "version=");
if (int.Parse(ver[1]) == int.Parse(appVersion))
{
tss1.Text = "Status : You currently have the latest version";
}
else
{
tss1.Text ="Status : A new version of app is available.";
System.Diagnostics.Process.Start("website.name");
}
}
catch (Exception ex)
{
tss1.Text = "Status : Update check failed.";
Debug.Write(ex.ToString());
}
I’m trying to use the above code to connect to webpage and pull down the latest version number for the app which it does just fine. My problem comes in when trying to compare the number found on the webpage to number provided by
appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
It seems that you want to check if the version of the running program is lower than the version string you just downloaded.
Instead of using integer comparison you could just do Version comparison.
Create a Version object from a string you download:
var downloadedVersion = new Version(versionStringDownloadedFromWeb);and compare this to the assemblys version:You can do this since the Version objects implements the IComparable interface.