且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用asp.net C#打开PDF文件时出现问题

更新时间:2022-06-18 23:59:35

Remove the "attachment; " portion of the "Content-Disposition" header and it should work.  You should also send the proper mime type (text/html for HTML documents, for instance), but it is not always necessary and application/octet-stream basically lets the browser figure it out.  Testing on my own machine with various file types, it opened up the new window and either loaded the file in the window (text, HTML), or required me to open it with the Download dialog, which closed the window when I downloaded the item.  One case did not close the window, which was a PDF file using "application/octet-stream" but by providing "application/pdf" it was correctly opened in the window. I am running IE 7.  Providing the mime type for the Office types (Excel's is "application/vnd.ms-excel" I believe) did not seem to help, but I am running the beta for Office 2007, so that might be a security feature to not display them within the browser and it still closed the window.

For the full list of "official" types: <a href="http://www.iana.org/assignments/media-types/">click here</a>


here are some useful links
<a href="http://www.beansoftware.com/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx">http://www.beansoftware.com/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx</a><a href="http://www.beansoftware.com/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx" target="_blank" title="New Window"></a>

<a href="http://forums.asp.net/t/1068814.aspx">another useful link</a>