Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I hope someone can help me with this. I am trying to open a pdf file in my asp.net 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.
Posted
Comments
Brij 15-Oct-10 12:51pm    
I dont know, what are you trying to achieve from this. Because this process will run on server and will open the file on server.I mean this process would not run on the client machines, for where your application is accessed

1 solution

XML
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>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900