這是下載文件的代碼。如何在新選項卡或窗口中打開PDF文件而不是下載它(使用asp.net)?
System.IO.FileStream fs = new System.IO.FileStream(Path+"\\"+fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] ar = new byte[(int)fs.Length];
fs.Read(ar, 0, (int)fs.Length);
fs.Close();
Response.AddHeader("content-disposition", "attachment;filename=" + AccNo+".pdf");
Response.ContentType = "application/octectstream";
Response.BinaryWrite(ar);
Response.End();
當執行此代碼時,它會要求用戶打開或保存該文件。代替這個,我需要打開一個新標籤或窗口並顯示該文件。我怎樣才能做到這一點?
注:
文件將沒有必要設在網站上的文件夾。它可能位於其他文件夾中。
你可以試試'內容處置:inline',而不是'attachment' - [參見這篇文章(http://dotanything.wordpress.com/2008/05/30/content-disposition-attachment-vs-inline /) –
這篇文章可以幫助你http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog –