我已将PDF文件上传到MS SQL Server数据库,当我将其作为字节从数据库中取回并尝试下载时,会下载一些文件但不是PDF文件。
我的代码:
Byte[] bytes = (Byte[])dt.Rows[0]["PDFDbColumnName"];
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=FileName");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
valid.Text = "File Downloaded";
Response.Flush();
Response.End();
答案 0 :(得分:0)
愚蠢的问题,但你确定它不仅仅是你没有在文件名中给它一个扩展名(所以它是一个未知的格式?)?
Response.AddHeader("content-disposition", "attachment;filename=FileName");
尝试
Response.AddHeader("content-disposition", "attachment;filename=FileName.pdf");