通过单击按钮打开PDF或Word文档

时间:2013-12-16 12:58:04

标签: c# asp.net

我正在开发一个KnoweldgeBase / Library,其中一个页面列出了与所选主题相关的PDF和Word文档。这些文件将上传到URL为“ / Interface / AdminUploads / Miscellaneous / FILENAME ”的文件夹中。

我通过一个表列出文件,其中每一行都有一个文件类型的图像,然后是文件标题,然后是发布的日期(全部通过另一个页面创建)。当我单击文档的图像时,如何打开PDF或Word文档?

4 个答案:

答案 0 :(得分:0)

试用此代码。

            string filepath ="/Interface/AdminUploads/Miscellaneous/FILENAME"; // Full Path of Pdf.
            WebClient client = new WebClient();
            Byte[] buffer = client.DownloadData(filepath);

            Response.ContentType = "application/pdf";
            Response.AddHeader("content-length", buffer.Length.ToString());
            Response.BinaryWrite(buffer);


            Response.Flush();
            Response.End();

答案 1 :(得分:0)

您需要将路径放在文件的网址中 您需要提供可以Server.MapPath获取完整路径的完整路径。

一些有用的链接

  1. How to open a file by clicking on HyperLink

答案 2 :(得分:0)

尝试简单的代码

Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "pdflocation/" + "Example.pdf"));

答案 3 :(得分:0)

我是通过......来实现的。

System.Diagnostics.Process.Start(@fileLocation);

在图像上运行此代码,点击并传入变量'fileLocation';

相关问题