我试图在点击浏览器中的链接时打开PDF。它实际上来自DB作为BLOB。但我得到错误:文件不以'pdf-'asp.net
开头这是我正在使用的代码,
if (dt.Rows.Count > 0)
{
string strExtenstion = dt.Rows[0]["DGN0101FILE_EXTENSION"].ToString();
byte[] bytFile = (byte[])dt.Rows[0]["DGN0101FILE"];
string fileName = dt.Rows[0]["DGN0101FILE_NAME"].ToString();
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
if (strExtenstion == ".doc" || strExtenstion == ".docx")
{
Response.ContentType = "application/vnd.ms-word";
}
else if (strExtenstion == ".xls" || strExtenstion == ".xlsx")
{
Response.ContentType = "application/vnd.ms-excel";
}
else if (strExtenstion == ".pdf")
{
Response.ContentType = "application/pdf";
}
Response.AddHeader("Content-Length", bytFile.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.BinaryWrite(bytFile);
Response.Flush();
Response.End();
Response.Clear();
}
答案 0 :(得分:0)
有效的PDF文件以%PDF-1.5
或类似名称开头。我的猜测是你的数据没有被正确存储或检索。