基本上在这段代码中,我正在检查xyz(dotcom)/update.xml是否有可用的新版本,如果新版本可用,它将从网站。这是第一次工作,现在每次我检查更新,它直接发送到“应用程序是最新的”代码尽管有一个新的版本可用的XML文件,我相信我的程序没有得到新的更新XML来自链接的文件,可能是什么问题?请检查下面的代码。****如果您需要更多信息,请告诉我。我的C#程序没有从网站获取最新的XML文件内容
public void checkForUpdate()
{
string download_url = "";
Version newVersion = null;
string xmlurl = "http://xyz.(dotcom)/update.xml";
try
{
XmlTextReader reader = new XmlTextReader(xmlurl);
reader.MoveToContent();
string elementname = "";
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "XYZ"))
{
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":
download_url = reader.Value;
break;
}
}
}
}
}
}
catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Exception", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
finally
{
if (reader != null)
{
reader.Close();
}
Version Applicationversion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
if (Applicationversion.CompareTo(newVersion) < 0)
{
DialogResult dialogresult = (MessageBox.Show("New Version: " + newVersion + " is available to download, would you like to download now?", "New Version Available", MessageBoxButtons.YesNo, MessageBoxIcon.Information));
{
if (dialogresult == DialogResult.Yes)
{
//System.Diagnostics.Process.Start(link);
Download dw = new Download();
dw.ShowDialog();
}
else if (dialogresult == DialogResult.No)
{
}
}
}
else
{
MessageBox.Show("Your application is up-to-date!", "Up-to-Date!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
检查请求是否被缓存 – toroveneno
此代码是相当'UGLY'并应细分为更好的可读性更小的方法。你有没有尝试通过调试器这个混乱..? – MethodMan
请看看我的终极块,我怀疑那里的问题,开放块开始和最后关闭......这可能是问题? –