c# - 无法在 Chrome 中打开下载的 PDF 文件
问题描述
这是我获取 PDF 文件的代码。当我尝试在 chrome 中打开我下载的 PDF 文件时,我收到一个错误对话框,其中显示“加载 PDF 文档失败”消息。
if (!string.IsNullOrEmpty(FileName))
{
var contentList = db.Output.Where(q => q.QID == id && q.FileName.Equals(FileName)).OrderBy(q => q.AQID).Select(q => q.TextValue).ToList();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < contentList.Count; i++)
{
sb.AppendFormat("{0}", contentList[i]);
// Response.WriteFile();
}
var byteArray = Encoding.ASCII.GetBytes(sb.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + FileName + "\"");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(byteArray);
Response.End();
}