基本上在此代码中我检查xyz(dotcom)/update.xml是否有新版本可用,如果新版本可用,它将从网站下载。它是第一次工作,现在每次我检查更新时,它直接发送到"应用程序是最新的"代码尽管xml文件中有新版本,我相信我的程序没有从链接获取新的更新的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);
}
}
}
}
答案 0 :(得分:0)
这解决了这个问题。
XmlTextReader reader = new XmlTextReader(xmlurl + "?" + Guid.NewGuid().ToString());
在互联网上找到某个地方,请解释一下,这里发生了什么?
我的最终阻止不正确,应该是
finally
{
if (reader != null)
{
reader.Close();
}
}