直接上代码
private bool pDownload()
{
IsOK = false;
System.Net.WebClient webclient = new System.Net.WebClient();
webclient.DownloadFile(pUrl, pFilePath);
System.IO.Stream str = webclient.OpenRead(pFilePath);
System.IO.StreamReader reader = new System.IO.StreamReader(str);
byte[] mbyte = new byte[str.Length + 1];
int allmybyte = (int)mbyte.Length;
int startmbyte = 0;
while (allmybyte > 0)
{
int m = str.Read(mbyte, startmbyte, allmybyte);
if (m == 0)
{
break;
}
startmbyte += m;
allmybyte -= m;
}
reader.Close();
System.IO.FileStream fstr = new System.IO.FileStream(pFilePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
fstr.Write(mbyte, 0, startmbyte);
str.Close();
fstr.Close();
IsOK = true;
return true;
}