主题:c#WinForm如何实现在线更新功能
c#WinForm如何实现在线更新功能,比如更新客户端的主程序及一些DLL之类的文件,我是想在服务器端有一个XML文件,当启动更新功能时,就读取XML并与客户端的XML进行比较版本的大小,一旦需要更新,服务器端将文件下载到本地,但是WinForm的下载怎么做的我不知道,希望能有高手指点一下,我自己有尝试写了一段,可以执行,但是如果是DLL文件,里面的大部分信息都会丢失
[color=FF0000]long fileLength;
string server = string.Format(@"{0}/Update/AutoUpdate.xml", ConfigurationManager.AppSettings["ServerUpdateAddress"]);
string client = string.Format("{0}\\{1}", Directory.GetCurrentDirectory(), ConfigurationManager.AppSettings["ClientUpdateAddress"]);
WebRequest request = WebRequest.Create(server);
WebResponse response = request.GetResponse();
fileLength = response.ContentLength;
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
byte[] byteData = new byte[fileLength];
stream.Read(byteData, 0, (int)fileLength);
//FileStream file = new FileStream(client, FileMode.OpenOrCreate);
FileStream file = new FileStream(client, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
file.Write(byteData, 0, byteData.Length);
file.Flush();
stream.Close();
reader.Close();
file.Close();[/color]
[color=FF0000]long fileLength;
string server = string.Format(@"{0}/Update/AutoUpdate.xml", ConfigurationManager.AppSettings["ServerUpdateAddress"]);
string client = string.Format("{0}\\{1}", Directory.GetCurrentDirectory(), ConfigurationManager.AppSettings["ClientUpdateAddress"]);
WebRequest request = WebRequest.Create(server);
WebResponse response = request.GetResponse();
fileLength = response.ContentLength;
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
byte[] byteData = new byte[fileLength];
stream.Read(byteData, 0, (int)fileLength);
//FileStream file = new FileStream(client, FileMode.OpenOrCreate);
FileStream file = new FileStream(client, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
file.Write(byteData, 0, byteData.Length);
file.Flush();
stream.Close();
reader.Close();
file.Close();[/color]