Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open PDF in Adobe Reader, not in Browser

Tags:

c#

asp.net

pdf

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?

like image 360
CompanyDroneFromSector7G Avatar asked Feb 22 '23 15:02

CompanyDroneFromSector7G


2 Answers

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();
like image 97
Yahia Avatar answered Feb 24 '23 05:02

Yahia


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

like image 43
Eonasdan Avatar answered Feb 24 '23 04:02

Eonasdan