这是我获取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();
}