我有一個顯示PDF文件的功能。即時通訊使用Internet Explorer,它是最新的。我試圖用兩臺電腦做到這一點。在一個瀏覽器中,它要求通過pdf閱讀器打開,而另一個瀏覽器打開一個標籤並顯示一個空白頁面。我已經嘗試了很多在互聯網上發現的代碼,即使在stackoverflow中。但沒有任何工作,因爲我想。這裏我添加了我的代碼。請看看它。爲什麼不在Internet Explorer中的獨立選項卡中查看PDF文件?
LinkButton的Click事件
protected void pdfViewLOP_Click(object sender, EventArgs e)
{
Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "viewPDF.aspx"));
}
代碼在新的網頁,其中的PDF應該顯示
protected void Page_Load(object sender, EventArgs e)
{
try
{
string name = Session["name"].ToString();
string FilePath = Server.MapPath("~/filesPDF/" + name);
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(FilePath);
if (buffer != null)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message);
}
}
我在文章中試過,但瀏覽器中沒有Adobe擴展installd – Mike