读书人

winform程序运用webservice自动更新

发布时间: 2013-01-06 15:44:47 作者: rapoo

winform程序使用webservice自动更新 急 急 急 急 急!!!
我在网上也看到一些资料
http://blog.sina.com.cn/s/blog_586b6c050100calj.html
找到那个方法,但是遇到一些问题,就是
<?xml version="1.0" encoding="utf-8" ?>
<product>
<version>1.0.1818.42821</version>
<description>修正一些Bug</description>
<filelist count="4" sourcepath="./update/">
<item name="City.xml" size="">
<value />
</item>
<item name="CustomerApplication.exe" size="">
<value />
</item>
<item name="Interop.SHDocVw.dll" size="">
<value />
</item>
<item name="Citys.xml" size="">
<value />
</item>
</filelist>
</product>
其中的city.xml和CustomerApplication.exe,Interop.SHDocVw.dll,Citys.xml是什么,是要改成我自己需要更新的文件的名称吗,然后,
private void Form1_Load(object sender, EventArgs e)
{
System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process p in ps)
{
//MessageBox.Show(p.ProcessName);
if (p.ProcessName.ToLower() == "demo")
{
p.Kill();
break;
}
}
XmlDocument doc = new XmlDocument();
doc.Load(Application.StartupPath + @"\update.xml");
XmlElement root = doc.DocumentElement;
XmlNode updateNode = root.SelectSingleNode("filelist");
string path = updateNode.Attributes["sourcepath"].Value;
int count = int.Parse(updateNode.Attributes["count"].Value);
for (int i = 0; i < count; i++)
{
XmlNode itemNode = updateNode.ChildNodes[i];
string fileName = itemNode.Attributes["name"].Value;
FileInfo fi = new FileInfo(fileName);


fi.Delete();
//File.Delete(Application.StartupPath + @"\" + fileName);
this.label1.Text = "正在更新: " + fileName + " (" + itemNode.Attributes["size"].Value + ") ...";
FileStream fs = File.Open(fileName, FileMode.Create, FileAccess.Write);
fs.Write(System.Convert.FromBase64String(itemNode.SelectSingleNode("value").InnerText), 0, int.Parse(itemNode.Attributes["size"].Value)); fs.Close();
}
label1.Text = "更新完成";
File.Delete(Application.StartupPath + @"\update.xml");
label1.Text = "正在重新启动应用程序...";
System.Diagnostics.Process.Start("demo.exe");
Close();
Application.Exit();
}

标志的地方,总是说我输入数据格式错误,希望有人知道,知道我一下,急
[解决办法]
你的数据是base 64处理过的字符串吗,肯定不是,那你用Convert.FromBase64String就会出错了。

多此一举了,直接用那个InnerText就可以了。

读书人网 >Web Service

热点推荐