如何在新标签或窗口中打开PDF文件,而不是(使用asp.net)下载呢? [英] How to open PDF file in a new tab or window instead of downloading it (using asp.net)?
本文介绍了如何在新标签或窗口中打开PDF文件,而不是(使用asp.net)下载呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是code下载该文件。
This is the code for downloading the file.
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();
在执行此code,它会要求用户打开或保存文件。取而代之的是,我需要的打开一个新的标签或窗口的,并显示该文件。我怎样才能做到这一点?
When this code is executed, it will ask user to open or save the file. Instead of this I need to open a new tab or window and display the file. How can I achieve this?
注意:
文件将不必要设在网站文件夹。它可能位于一个其他文件夹中。
File won't necessary be located in the website folder. It might be located in an other folder.
推荐答案
,你应该看看的 Htt的presponse.TransmitFile
Response.ContentType = "Application/pdf";
Response.TransmitFile(pathtofile);
如果您希望PDF在新窗口中打开,你将不得不在新窗口中打开下载页面,比如像这样的:
If you want the PDF to open in a new window you would have to open the downloading page in a new window, for example like this:
<a href="viewpdf.aspx" target="_blank">View PDF</a>
这篇关于如何在新标签或窗口中打开PDF文件,而不是(使用asp.net)下载呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文