來源:http://www.cnblogs.com/tengs2000/archive/2009/02/23/1396646.htmlhtml
1、直接顯示,使用的仍是原頁面的URLapp
1 Response.ContentType = "application/pdf"; 2 Response.Clear(); 3 Response.TransmitFile(@"SharePoint.pdf"); 4 Response.End();
2、以PDF文件作爲URL進行顯示ide
Response.Redirect("Sharepoint.pdf");spa
3、點擊進行下載.net
1 Response.ClearHeaders(); 2 Response.ContentType = "application/pdf"; 3 Response.Clear(); 4 Response.AppendHeader("Content-Disposition", "attachment;Filename=SharePoint.pdf"); 5 Response.TransmitFile(@"SharePoint.pdf"); 6 Response.End();
注意:上面SharePoint.pdf是pdf文件的名字與路徑。(如今是當前目錄,故目錄沒有寫「 ./ 」 而已。)code
4、在一個頁面中嵌入一個PDF顯示框server
例如:在Default4.aspx裏面顯示一個框,能夠使用iframe。htm
<iframe runat ="server" src="getPdfFile.aspx?filename=./pdf/通知.pdf" width="800px" height="600px" ></iframe>blog
另外再寫一個getPdfFile.aspx頁面,寫其pageload事件:事件
1 protected void Page_Load(object sender, EventArgs e) 2 { 3 string fileName = Request["fileName"]; 4 Response.ContentType = "application/pdf"; 5 Response.Clear(); 6 Response.TransmitFile(@""+fileName); 7 Response.End(); 8 }
嗯,這個作法是參考了http://bbs.csdn.net/topics/340192312裏面的討論。
但是拷貝別人的代碼過來,運行不了,只好用了上面第一種的作法。(可能不是很好。)
原來的代碼: