在浏览器中打开上传的PDF和Excel文件 [英] Open uploaded PDF and Excel file in Browser

查看:110
本文介绍了在浏览器中打开上传的PDF和Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Linkbutton的click事件上在新窗口或浏览器的同一窗口中显示上载的文件.

我可以获取文件的路径.

文件是否存在已被检查,但是我无法打开文件.

文件上传到 Inetpub \ wwwroot \
(即 C:\ Inetpub \ wwwroot \ ApplicationFiles \ Template \ 1.pdf )
文件路径保存在数据库中.

预先感谢!

I need to display uploaded files in new window or same window of browser on Linkbutton''s click event.

I''m able to get path of file.

Whether file exists or not is already checked, but I''m not able to OPEN file.

Files are uploaded at Inetpub\wwwroot\
(i.e. C:\Inetpub\wwwroot\ApplicationFiles\Template\1.pdf)
File path is saved in database.

Thanks in Advance!

推荐答案

根据您尝试的方法,这可能是一个很难回答的问题.

请提供代码,以便对其进行研究.
(不是完整的代码转储!,只是相关区域:))

没有打开PDF的理由不明显(除非除非未加载PDF阅读器?否则我认为情况并非如此)

另一种方法是根本不加载PDF,而一旦用户将PDF加载到浏览器中,让用户选择保存(这是我在公司网站上喜欢的方法).

无论哪种方式,代码都将使我们能够为您提供更好,更合适的答案.

干杯.





如果有帮助,请标记!
This could be a difficult question to answer, depending on the approaches you have attempted.

Please provide the code so that it can be studied.
(Not a complete codedump!, Just the relevent area :) )

There should be no readily apparent reason why a PDF is not opening, (Unless perhaps there is no PDF reader loaded? I presume this is not the case)

Another approach is to not load a PDF at all, and let the user choose to save once he has loaded it to his browser (This is an approach I favour with my company''s website).

Either way, code would allow us to provide a better, more suitable answer for you.

Cheers.





Mark up if helpful!




上载后,请尝试使用以下代码在浏览器中打开pdf文件

Hi,

try this code to open pdf files in browser after uploading

Response.Clear();
Response.AddHeader("content-type", "application/pdf");
Response.WriteFile(Server.MapPath("~/testingimages/sample2.pdf"));
Response.End();



在这里,您不得不提到内容类型.

现在所有浏览器都支持pdf文件以直接显示


最好的



Here you''ve to mention the content type .

now all browsers supports pdf files to display directly


All the Best


这篇关于在浏览器中打开上传的PDF和Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆