下载用于查看的Pdfs名称不正确

编程入门 行业动态 更新时间:2024-10-27 04:34:44
本文介绍了下载用于查看的Pdfs名称不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在下载PDF以在浏览器中在母版页表单的内容部分中查看。我希望我的用户能够单击下载按钮或右键单击并保存为PDF的名称。 我认为我的问题是pdf文件在网络共享上,用户无法直接访问。我发现如果文件可以直接访问(例如mywebsite/PdfFile.pdf),下载到用户的名称与pdf文件相同,并且所有下载功能都在那里。但是,我的所有文件都在网络共享上,我必须使用.aspx页面来提供pdf文件(例如mywebsite/PdfServer.aspx?file=PdfFile.pdf)。当我这样做时,显示的页面以.aspx文件命名,我无法直接以PDF格式下载文件。 任何有助于指出正确方向的帮助表示赞赏。 拉里 我的尝试: 我确实知道我可以将.aspx页面保存为PDF但这不是一个好的解决方案。 I确实找到了一些在独立页面中显示PDF的代码:

I'm downloading a PDF to be viewed on the browser within the content section of a master page form. I would like my user to have the ability to click a download button or right click and SAVE AS the name of the PDF. I think my problem is that the pdf files are on a network share and cannot be accessed directly by the user. I found that if the files were directly accessible ( for example mywebsite/PdfFile.pdf), the name downloaded to the user is the same as the pdf file and all the download capability is there. However, all my files are on network shares and I must use an .aspx page to serve up the pdf file ( for example mywebsite/PdfServer.aspx?file=PdfFile.pdf). When I do this, the displayed page is named after the .aspx file and I cannot directly download the file as a pdf. Any help to be pointed in the right direction appreciated. Larry What I have tried: I did figure out that I could save the .aspx page as a PDF but that's not a good solution. I did locate some behind code that displayed the PDF in a standalone page:

Response.Redirect("~PdfFile.pdf");

满足我的所有要求,例如显示的正确名称和存在的下载功能。但是,这似乎仅在PDF位于网站文件夹中时才起作用。我的文件在网络驱动器上,所以我必须使用aspx或ashx页面来传输它们。 我也尝试使用类似下面的东西,它工作得很好,文档显示在带有下载选项的PDF框架中......

That meets all my requirements like the right name being displayed and the download capability being present. However, this appears to only work when the PDF is within the website folders. My files are on network drives so I have to use aspx or ashx pages to transmit them. I've also tried to use something like the following and it worked great, the document displayed within a PDF frame with download options...

<asp:HyperLink ID="lnkPDF" runat="server" NavigateUrl="~PdfFile.pdf" Target="_blank">View PdfFile.pdf</asp:HyperLink>

但是当我将NavigateURL更改为我的aspx页面提供PDF文件时显示,但没有aspx扩展,也没有下载或打印功能。 我玩过TransmitFile,WriteFile,contentTypes和Content-Disposition(附件) & inline)标题没有成功。

but when I changed the NavigateURL to my aspx page serving up the PDF the file would display but with the aspx extension and none of the download or print features available. I've played around with the TransmitFile, WriteFile, contentTypes and Content-Disposition (attachment & inline) headers with no success.

推荐答案

这是你给它一个文件名的方法。 This is how you give it a filename. Response.AddHeader("content-disposition", "attachment; filename=" + fileName);

大多数浏览器都会使用它来默认保存时显示的名称。

Most browsers will use that to default the name that is displayed when saving.

更多推荐

下载用于查看的Pdfs名称不正确

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

发布评论

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

>www.elefans.com

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