代码如下,最好还需要加上文件版本判断,确定是不是同一个文件,不要是牛头马面了
fileStream = new FileStream(Path,FileMode.Append,FileAccess.Write);
inStream = null;
try
{
HttpWebRequest myre=(HttpWebRequest)WebRequest.Create(URL);
if(fileStream.Length == myre.ContentLength)
{
MessageBox.Show("你以完成下载该程序了","ok");
return;
}
myre.AddRange(Convert.ToInt32(fileStream.Length));//接上次下载的字节开始下载文件
HttpWebResponse response = (HttpWebResponse)myre.GetResponse();
inStream =response .GetResponseStream();
this.progressBar1.Maximum = total;
this.progressBar1.Minimum =0;
int length = 1024;
byte[] buffer = new byte[1025];
int readerLength = 0,currentLength=0;
while((readerLength =inStream.Read(buffer,0,length))> 0)
{
currentLength += readerLength ;
fileStream.Write(buffer,0,readerLength);
this.progressBar1.Value =currentLength + countByte;
}
fileStream.Close();
inStream.Close();
File.Delete(Application.StartupPath +@"\FileLength.txt");
MessageBox.Show("down 成功","ok");
inStream = null;
try
{
HttpWebRequest myre=(HttpWebRequest)WebRequest.Create(URL);
if(fileStream.Length == myre.ContentLength)
{
MessageBox.Show("你以完成下载该程序了","ok");
return;
}
myre.AddRange(Convert.ToInt32(fileStream.Length));//接上次下载的字节开始下载文件
HttpWebResponse response = (HttpWebResponse)myre.GetResponse();
inStream =response .GetResponseStream();
this.progressBar1.Maximum = total;
this.progressBar1.Minimum =0;
int length = 1024;
byte[] buffer = new byte[1025];
int readerLength = 0,currentLength=0;
while((readerLength =inStream.Read(buffer,0,length))> 0)
{
currentLength += readerLength ;
fileStream.Write(buffer,0,readerLength);
this.progressBar1.Value =currentLength + countByte;
}
fileStream.Close();
inStream.Close();
File.Delete(Application.StartupPath +@"\FileLength.txt");
MessageBox.Show("down 成功","ok");