【发布时间】:2017-01-20 19:55:15
【问题描述】:
我想显示一个 pdf。我当前的代码使用 pdf 阅读器显示。但我想在浏览器的单独选项卡中打开它。我该怎么做?我在网页中有一个链接按钮。我已经在 onClick 方法中设置了这个。如何使用后端代码打开它? (不使用 aspx 中的链接)
这是我的代码
string name = ddlAppealList.SelectedValue.ToString();
int refNo = Convert.ToInt32(name);
string FilePath = Server.MapPath("~/filesPDF/" + refNo + ".pdf");
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if (FileBuffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
【问题讨论】:
-
预先在新窗口中打开目标,例如
<a href="viewpdf.aspx" target="_blank">View PDF</a>。来自How to open PDF file in a new tab or window instead of downloading it (using asp.net)? -
这种行为是否也与浏览器配置和/或内联 pdf 查看器的可用性有关?