4
votes

when clicked from a link on an email, the following code causes a PDF document to open in the browser:

Response.ContentType = mime;
Response.WriteFile(path);
HttpContext.Current.ApplicationInstance.CompleteRequest();

Is there any way to force the client to open it natively in the Adobe Acrobat/reader?

3
I believe the open in browser vs open in adobe reader is a browser/user setting. It's unlikely you can work around that through C#. - KP.
The HTTP spec allows you to specify the type of binary information being sent but there is no way to specify a specific application to process the content. At best, you can force the user to download the PDF and manually open it which should open in their native PDF viewer which for many people is Adobe Acrobat/Reader. - Chris Haas

3 Answers

5
votes

How the client behaves depends on several things including client-side settings... you could try this

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename="+filePath); 
Response.WriteFile(path);
HttpContext.Current.ApplicationInstance.CompleteRequest();
2
votes
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.pdf");
Response.TransmitFile( Server.MapPath("~/images/sailbig.pdf") );
Response.End();

here's some good information to help: Downloading a File with a Save As Dialog in ASPNET, and c# dynamically rename file upon download request, and Handling file downloads using ASP.NET MVC if you're using MVC

1
votes

The best thing you can do is adding a content-disposition header. This should cause a download file dialog to appear.

Response.AddHeader("content-disposition", "attachment;filename=xxx.pdf");