HTTP下载(doc)


System.Net.WebClient webClient=new System.Net.WebClient();
Stream stream = webClient.OpenRead(SourceURL);
byte[] arrByte = new byte[1024];
long completedByteCount = 0;
if (File.Exists(DestPath))
{
File.Delete(DestPath);
}
FileStream fStream = new FileStream(DestPath,FileMode.CreateNew,FileAccess.Write);
while(true)
{
int readCnt = stream.Read(arrByte,0,1024);
if(readCnt==0) break;     
fStream.Write(arrByte,0,readCnt);
completedByteCount += readCnt;
double percent=(int)((float)completedByteCount / FileLength*100) ;
CompletedProseccEventArgs e=new CompletedProseccEventArgs(percent,completedByteCount);
OnCompletedProsecc(e);
}             
stream.Close();
fStream.Close();

里面有些代码是为了控件进度条

你可能感兴趣的:(http)