在Adobe Reader中打开PDF,而不是在浏览器中打开

时间:2012-01-31 16:23:13

标签: c# asp.net pdf

从电子邮件中的链接点击时,以下代码会导致PDF文档在浏览器中打开:

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

有没有办法强制客户端在Adobe Acrobat / reader中本地打开它?

3 个答案:

答案 0 :(得分:5)

客户端的行为方式取决于几个方面,包括客户端设置......你可以试试这个

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename="+filePath); 
Response.WriteFile(path);
HttpContext.Current.ApplicationInstance.CompleteRequest();

答案 1 :(得分:2)

Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename=SailBig.pdf");
Response.TransmitFile( Server.MapPath("~/images/sailbig.pdf") );
Response.End();

这里有一些很好的信息可以提供帮助:Downloading a File with a Save As Dialog in ASPNETc# dynamically rename file upon download requestHandling file downloads using ASP.NET MVC如果你正在使用MVC

答案 2 :(得分:1)

您可以做的最好的事情是添加内容处置标头。这将导致出现下载文件对话框。

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