日期:2014-05-17 浏览次数:20432 次
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();
}
}