C# 使用XML创建应用程序更新检查器
在你问我是否看过谷歌之前,让我回答是的,我已经阅读了一页又一页。一个接一个的网站,我无法获得我需要的信息 我正在尝试为我的应用程序制作一个非常简单的更新检查器。它将解析在线xml文件,并在某些地方显示数据。以及能够解析出下载位置的链接(不是ftp或任何东西,而是类似于文件主机的东西,因为我的托管计划不允许ftp文件超过3MB) 不管怎样,到目前为止,我得到的是: XML代码:C# 使用XML创建应用程序更新检查器,c#,xml,parsing,auto-update,C#,Xml,Parsing,Auto Update,在你问我是否看过谷歌之前,让我回答是的,我已经阅读了一页又一页。一个接一个的网站,我无法获得我需要的信息 我正在尝试为我的应用程序制作一个非常简单的更新检查器。它将解析在线xml文件,并在某些地方显示数据。以及能够解析出下载位置的链接(不是ftp或任何东西,而是类似于文件主机的东西,因为我的托管计划不允许ftp文件超过3MB) 不管怎样,到目前为止,我得到的是: XML代码: <code> <Info> <Version>2.8.0.0&l
<code>
<Info>
<Version>2.8.0.0</Version>
<Link>www.filehost.com</Link>
<Description>Added New Features To GUI</Description>
</Info>
</code>
我希望应用程序能够以这种方式解析xml
<Version>2.8.0.0</Version> Will change the text for "lblUpdateVersion" like how I got the current version label set in the InitializeComponent();
<Description>Added New Features To GUI</Description> to be parsed out into the "textDescription" Which I can probably do myself.
<Link>www.filehost.com</Link> Will parse into the button control so when pressed will open up the users default browser and follow the link.
2.8.0.0将更改“lblUpdateVersion”的文本,就像我如何在InitializeComponent()中设置当前版本标签一样;
在GUI中添加了新功能,可以解析为“textDescription”,我自己也可以这样做。
www.filehost.com将解析到按钮控件中,因此当按下按钮时,将打开用户默认浏览器并跟随链接。
我已经在自己的应用程序中完成了这项工作
首先,在Web主机上存储一个保存更新程序信息的XML文件。矿山位于,结构如下:
<versioninformation>
<latestversion>1.2.0.0</latestversion>
<latestversionurl>http://www.getquitter.com/quitter-1.2.0.zip</latestversionurl>
<filename>quitter-1.2.0.zip</filename>
</versioninformation>
接下来,调用此方法获取xml并加载到xml文档中
Dim VersionInfo As New System.Xml.XmlDocument
VersionInfo.LoadXml(GetWebPage("http://www.getquitter.com/version.xml"))
加载version.xml后,您现在可以解析出需要的各个数据片段,以确定是否需要获取新版本
Dim LatestVersion As New Version(QuitterInfoXML.SelectSingleNode("//latestversion").InnerText)
Dim CurrentVersion As Version = My.Application.Info.Version
If LatestVersion > CurrentVersion Then
''download the new version using the Url in the xml
End If
我的应用程序就是这样做的。如果您愿意(这是一个开源应用程序),您可以下载源代码,如果您想将其用作模型。它在。希望这有帮助 我在自己的一个应用程序中做到了这一点
using System;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.IO;
using System.Diagnostics;
namespace SAM
{
public partial class UpdateCheck : DevExpress.XtraEditors.XtraForm
{
public UpdateCheck()
{
InitializeComponent();
lblCurrentVersion.Text = "Current Version: " + Application.ProductVersion;
}
private void MainForm_Shown(object sender, EventArgs e)
{
BringToFront();
}
public static string GetWebPage(string URL)
{
System.Net.HttpWebRequest Request = (HttpWebRequest)(WebRequest.Create(new Uri(URL)));
Request.Method = "GET";
Request.MaximumAutomaticRedirections = 4;
Request.MaximumResponseHeadersLength = 4;
Request.ContentLength = 0;
StreamReader ReadStream = null;
HttpWebResponse Response = null;
string ResponseText = string.Empty;
try
{
Response = (HttpWebResponse)(Request.GetResponse());
Stream ReceiveStream = Response.GetResponseStream();
ReadStream = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8);
ResponseText = ReadStream.ReadToEnd();
Response.Close();
ReadStream.Close();
}
catch (Exception ex)
{
ResponseText = string.Empty;
}
return ResponseText;
}
private void BtnChkUpdate_Click(object sender, EventArgs e)
{
System.Xml.XmlDocument VersionInfo = new System.Xml.XmlDocument();
VersionInfo.LoadXml(GetWebPage("http://www.crimson-downloads.com/SAM/UpdateCheck.xml"));
lblUpdateVersion.Text = "Latest Version: " + (VersionInfo.SelectSingleNode("//latestversion").InnerText);
textDescription.Text = VersionInfo.SelectSingleNode("//description").InnerText;
}
private void simpleButton2_Click(object sender, EventArgs e)
{
Process process = new Process();
// Configure the process using the StartInfo properties.
process.StartInfo.FileName = "http://www.crimson-downloads.com/SAM/Refresh.htm";
process.StartInfo.Arguments = "-n";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.Start();
}
}
}
首先,在Web主机上存储一个保存更新程序信息的XML文件。矿山位于,结构如下:
<versioninformation>
<latestversion>1.2.0.0</latestversion>
<latestversionurl>http://www.getquitter.com/quitter-1.2.0.zip</latestversionurl>
<filename>quitter-1.2.0.zip</filename>
</versioninformation>
接下来,调用此方法获取xml并加载到xml文档中
Dim VersionInfo As New System.Xml.XmlDocument
VersionInfo.LoadXml(GetWebPage("http://www.getquitter.com/version.xml"))
加载version.xml后,您现在可以解析出需要的各个数据片段,以确定是否需要获取新版本
Dim LatestVersion As New Version(QuitterInfoXML.SelectSingleNode("//latestversion").InnerText)
Dim CurrentVersion As Version = My.Application.Info.Version
If LatestVersion > CurrentVersion Then
''download the new version using the Url in the xml
End If
我的应用程序就是这样做的。如果您愿意(这是一个开源应用程序),您可以下载源代码,如果您想将其用作模型。它在。希望这有帮助
using System;
using System.Windows.Forms;
using System.Xml;
using System.Net;
using System.IO;
using System.Diagnostics;
namespace SAM
{
public partial class UpdateCheck : DevExpress.XtraEditors.XtraForm
{
public UpdateCheck()
{
InitializeComponent();
lblCurrentVersion.Text = "Current Version: " + Application.ProductVersion;
}
private void MainForm_Shown(object sender, EventArgs e)
{
BringToFront();
}
public static string GetWebPage(string URL)
{
System.Net.HttpWebRequest Request = (HttpWebRequest)(WebRequest.Create(new Uri(URL)));
Request.Method = "GET";
Request.MaximumAutomaticRedirections = 4;
Request.MaximumResponseHeadersLength = 4;
Request.ContentLength = 0;
StreamReader ReadStream = null;
HttpWebResponse Response = null;
string ResponseText = string.Empty;
try
{
Response = (HttpWebResponse)(Request.GetResponse());
Stream ReceiveStream = Response.GetResponseStream();
ReadStream = new StreamReader(ReceiveStream, System.Text.Encoding.UTF8);
ResponseText = ReadStream.ReadToEnd();
Response.Close();
ReadStream.Close();
}
catch (Exception ex)
{
ResponseText = string.Empty;
}
return ResponseText;
}
private void BtnChkUpdate_Click(object sender, EventArgs e)
{
System.Xml.XmlDocument VersionInfo = new System.Xml.XmlDocument();
VersionInfo.LoadXml(GetWebPage("http://www.crimson-downloads.com/SAM/UpdateCheck.xml"));
lblUpdateVersion.Text = "Latest Version: " + (VersionInfo.SelectSingleNode("//latestversion").InnerText);
textDescription.Text = VersionInfo.SelectSingleNode("//description").InnerText;
}
private void simpleButton2_Click(object sender, EventArgs e)
{
Process process = new Process();
// Configure the process using the StartInfo properties.
process.StartInfo.FileName = "http://www.crimson-downloads.com/SAM/Refresh.htm";
process.StartInfo.Arguments = "-n";
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
process.Start();
}
}
}
简明扼要。谢天谢地,我在使用xml的其他东西上遇到了麻烦,但是在你给我的帮助下,我也能够将这些知识应用到这方面,并使它工作起来
简明扼要。谢天谢地,我在使用xml的其他东西上遇到了问题,但是在你给我的帮助下,我也能够将这些知识应用到这方面,并使它能够正常工作。你使用的是.NET的哪个版本?你使用的是.NET的哪个版本?很抱歉回复得太晚。这正是我想要的。我使用了您的xml格式,但对它做了一个小小的更改,以便添加更改日志。我还将您添加到“关于”页面和您网站的链接。很高兴它对您有效,非常感谢您在“关于”页面上的提及!很抱歉回信晚了。这正是我想要的。我使用了您的xml格式,但对它做了一个小小的更改,以便添加更改日志。我还将您添加到“关于”页面和您网站的链接。很高兴它对您有效,非常感谢您在“关于”页面上的提及!