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

编程入门 行业动态 更新时间:2024-10-26 00:29:12
本文介绍了使用asp C#打开PDF文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望有人可以帮助我.我正在尝试使用c#在asp应用程序中打开pdf文件.当我在装有Visual Studio的PC上运行它时,它可以正常工作.当我尝试在服务器上运行它时,该文档没有打开.如果我查看任务管理器,该过程确实会启动,并且我的网页会闪烁,好像正在刷新,但pdf文档无法打开.我尝试了两种不同的方法,但均无效.

I hope someone can help me with this. I am trying to open a pdf file in my asp application using c#. When I run it on my PC with Visual Studio, it works fine. When I try to run it on the server, the document doesn''t open. If I look at the Task Manager, the process does start and my web page flickers as if it is refreshing but the pdf document does not open up. I have tried two different methods and neither works.

string FilePath = Request.PhysicalApplicationPath.ToString() + "Pages\\UserGuide\\UserGuide.pdf"; ProcessStartInfo startInfo = new ProcessStartInfo(FilePath); Process.Start(startInfo);

and

string FilePath = Request.PhysicalApplicationPath.ToString() + "Pages\\UserGuide\\UserGuide.pdf"; System.Diagnostics.Process Proc = new System.Diagnostics.Process(); Proc.EnableRaisingEvents = true; Proc.StartInfo.FileName = FilePath; Proc.StartInfo.Arguments = "AcroRd32.exe"; Proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; Proc.StartInfo.CreateNoWindow = false; Proc.Start();

另外,如何以及何时取消该进程? 预先感谢您的任何建议.

Also, how and when do I kill the process? Thanks in advance for any suggestions.

推荐答案

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="www.iana/assignments/media-types/">click here</a> here are some useful links <a href="www.beansoftware/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx">www.beansoftware/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx</a><a href="www.beansoftware/ASP.NET-Tutorials/PDF-View-Custom-Control.aspx" target="_blank" title="New Window"></a> <a href="forums.asp/t/1068814.aspx">another useful link</a>

更多推荐

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

本文发布于:2023-11-17 17:13:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1610420.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   asp   net   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!