Đây là mã để tải xuống tệp.Cách mở tệp PDF trong tab hoặc cửa sổ mới thay vì tải xuống tệp (sử dụng 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();
Khi mã này được thực thi, nó sẽ yêu cầu người dùng mở hoặc lưu tệp. Thay vào đó, tôi cần phải mở tab hoặc cửa sổ mới và hiển thị tệp. Làm thế nào tôi có thể đạt được điều này?
LƯU Ý:
File sẽ không cần thiết được đặt trong thư mục trang web. Nó có thể nằm trong một thư mục khác.
Bạn có thể thử 'nội dung bố trí: inline' thay vì' tệp đính kèm' - [Xem bài viết này] (http://dotanything.wordpress.com/2008/05/30/content-disposition-attachment-vs-inline /) –
bài viết này có thể giúp bạn http://aspalliance.com/259_downloading_files__forcing_the_file_download_dialog –