为什么asp.net 下载文件失败?
为什么下载文件时,原文件是几百字节下载要保存的时候只有16字节,除非文件小于16字节
(文件上传后是保持在数据库中,用image字段保存的)
主要代码如下:
this.Response.Clear(); //清除缓冲区流中的所有内容输出
this.Response.ClearHeaders(); //清除缓冲区流中的所有头
this.Response.Buffer = false; //设置缓冲输出为false
//设置输出流的 HTTP MIME 类型为application/octet-stream
this.Response.ContentType = "application/octet-stream";
//将 HTTP 头添加到输出流
this.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(upFileMdl.FileName, System.Text.Encoding.UTF8));
//将指定的文件直接写入 HTTP 内容输出流。
this.Response.BinaryWrite(upFileMdl.LoadFile);
this.Response.Flush(); //向客户端发送当前所有缓冲的输出
this.Response.End(); //将当前所有缓冲的输出发送到客户端