Asp.net MemoryStream下载未弹出下载对话框
我想以流的方式下载文件,使用的方法如下:
private void WriteStreamToResponse(MemoryStream ms)
{
if (ms.Length > 0)
{
string filename = DateTime.Now.ToFileTime().ToString() + ".zip";
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("Content-Length", ms.Length.ToString());//文件长度
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);//文件名称
Response.ContentType = "application/octet-stream";//获取或设置HTTP类型
byte[] buffer = new byte[65536];
ms.Position = 0;
int num;
do
{
num = ms.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, num);
}
while (num > 0);
Response.Flush();
}
}