我到達的解決方案是這樣的:
創建一個新的ASP.NET Web窗體(我叫雷爲BinaryData.aspx)作爲對PDF的佔位符。在後面的代碼,唯一的方法應該是Page_Load中,它看起來像:
protected void Page_Load(object sender, System.EventArgs e)
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Cache-Control", "no-cache");
//Get the physical path to the file.
string FilePath = (string)Session["fileLocation"];
if (FilePath != null)
{
string FileName = Path.GetFileName(FilePath);
Response.AppendHeader("Content-Disposition", "attachment; filename="+FileName);
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
}
}
的PDF在頁面通過名爲「fileLocation」會話變量傳遞。所以,我必須設置該變量,然後致電Response.Redirect("BinaryData.aspx")
。
它不會自動打印,但會觸發下載PDF而不離開當前頁面(這對我來說已經足夠了)。
這聽起來像它將會在更加複雜的方向 - 它當然可以工作,但我寧願保持獨立的PDF網頁的行爲。 – 2009-08-03 17:33:40