流方式下载代码,如下:
byte[] buffer = new byte[102400L];
HttpContext.Current.Response.Clear();
FileStream fileStream = File.OpenRead(fileInfo.FullName);
long num = fileStream.Length;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename="
+ HttpUtility.UrlEncode(savename, Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
while (num > 0L && HttpContext.Current.Response.IsClientConnected)
{
int num2 = fileStream.Read(buffer, 0, Convert.ToInt32(102400L));
HttpContext.Current.Response.OutputStream.Write(buffer, 0, num2);
HttpContext.Current.Response.Flush();
num -= (long)num2;
}
HttpContext.Current.Response.Close();
fileStream.Close();
fileStream.Dispose();