doc.Load(Server.MapPath("update.xml"));www.lunwenwang.com
XmlElement root = doc.DocumentElement;
//看看有几个文件需要更新
XmlNode updateNode = root.SelectSingleNode("filelist");
string path = updateNode.Attributes["sourcepath"].Value;
int count = int.Parse(updateNode.Attributes["count"].Value);
//将xml中的value用实际内容替换
for(int i=0;i= updateNode.ChildNodes[i];
string fileName = path + itemNode.Attributes["name"].Value;
FileStream fs = File.OpenRead(Server.MapPath(fileName));
itemNode.Attributes["size"].Value = fs.Length.ToString();
BinaryReader br = new BinaryReader(fs);
//这里是文件的实际内容,使用了Base64String编码
itemNode.SelectSingleNode("value").InnerText = Convert.ToBase64String(br.ReadBytes((int)fs.Length),0,(int)fs.Length);
br.Close();
fs.Close();
}
return doc;
}4)编写客户端的UpDate
方法 首先引用此Web Services,例如命名为:WebSvs,
string nVer = Start.GetService.GetVer();
if(Application.ProductVersion.CompareTo(nVer)<=0)
update();
在本代码中Start.GetService是WebSvs的一个静态实例。功能是:首先检查版本,将结果与当前版本进行比较,如果为新版本则执行UpDate方法。
update的作用是将升级的XML文件下载下来,保存为执行文件目录下的一个Update.xml文件。任务完成,退出程序,等待Update.Exe 来进行升级。
void update()
{
this.statusBarPanel1.Text = "正在下载...";
System.Xml.XmlDocument doc = ((System.Xml.XmlDocument)Start.GetService.GetUpdateData());
doc.Save(Application.StartupPath + @"\update.xml");
System.Diagnostics.Process.Start(Application.StartupPath + @"\update.exe");
Close();
Application.Exit();
}
(5)编写客户端的Update.Exe
Update.exe的功能主要是:首先就是找到主进程;如果没有关闭,则用Process.Kill()来关闭主程序。然后则用一个XmlDocument来Load程序生成的update.xml文件。用xml文件里指定的路径和文件名来生成指定的文件,在这之前先前已经存在的文件删除。更新完毕后,则重新启动主
转贴于 酷文网-论文下载中心 http://www.coolwen.net
共4页: 上一页 [1] 2 [3] [4] 下一页
网摘收藏: