现在做WINFORM的人总会碰到系统自动更新的问题,在网上找了下有两个方法比较实用.
1.用M$的CLICKONCE技术 ,可参考下面的连接
http://dev.yesky.com/msdn/155/2033155_1.shtml
不过这个好象是2005的...所以象我用2003就麻烦了
2.用webservice作为更新服务器
程序启动的时候检测服务器,然后定义一个版本文件,检测版本文件,低的时候就下载,方便快捷,只是我做没下载过程序文件,不知道行不行.下边是关键的部分.这个是我现在在用的,暂时运行正常.
/// <summary>
/// getBinaryFile:返回所给文件路径的字节数组。
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public byte[] getBinaryFile(string filename)
{
if(File.Exists(Server.MapPath("xml//"+filename)))
{
try
{
///打开现有文件以进行读取。
FileStream s = File.OpenRead(Server.MapPath("xml//"+filename));
return ConvertStreamToByteBuffer(s);
}
catch(Exception e)
{
return new byte[0];
}
}
else
{
return new byte[0];
}
}
/// <summary>
/// ConvertStreamToByteBuffer:把给定的文件流转换为二进制字节数组。
/// </summary>
/// <param name="theStream"></param>
/// <returns></returns>
public byte[] ConvertStreamToByteBuffer(System.IO.Stream theStream)
{
int b1;
System.IO.MemoryStream tempStream = new System.IO.MemoryStream();
while((b1=theStream.ReadByte())!=-1)
{
tempStream.WriteByte(((byte)b1));
}
return tempStream.ToArray();
}