求助 ASP.NET下载数据库中文件
Response.Buffer = true;
Response.Clear(); Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.FileName.ToString() + "." + file.FileType.ToString(), Encoding.UTF8));
Response.AppendHeader("Content-Length", file.File.Length.ToString());
Response.BinaryWrite((Byte[])file.File);
Response.Flush();
Response.End();
从数据库中读出byte类型的file.File,但是下载的文件保存到本地后,文本文档txt,world的内容是System.Byte[]
是什么原因啊..求解 --------------------编程问答-------------------- //以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
--------------------编程问答--------------------
这个我有用MemoryStream尝试过.
byte[] bytes = new byte[file.File.Length];
MemoryStream m = new MemoryStream(file.File);
m.Read(bytes, 0, file.File.Length);
m.Close();
Response.Buffer = true;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.FileName.ToString() + "." + file.FileType.ToString(), Encoding.UTF8));
Response.AppendHeader("Content-Length", file.File.Length.ToString());
Response.BinaryWritebytes);
Response.Flush();
Response.End();
但是结果得到的文本的内容还是System.Byte[]
补充:.NET技术 , ASP.NET