如何在asp.net页面上查看pdf或word文件

如何在asp.net页面上查看pdf或word文件

问题描述:

早上好

实际上,我无法在asp.net网络表单上查看PDF或Word文件.

首先我正在服务器上上传文件.

第二个我将在网格视图中看到所有文件名,当我选择特定文件时,该文件应以新的Web形式打开.

因此,请帮助我解决此问题.

Hi good morning

Actually I am not able to view the PDFs or word file on asp.net web-form.

First I am uploading the file on server.

Second I will see all the file names in grid-view and when I select the particular file than that file should be open in new web-form.

So please help me out to solve this problem.

只需检查一下:


未安装Acrobat Reader的ASP.NET PDF Viewer用户控件客户端或服务器 [ ^ ]
Just Check :


ASP.NET PDF Viewer User Control Without Acrobat Reader Installed on Client or Server[^]


嗨 您可以使用两种方式在Web表单上显示pdf

1)
使用System.Net;

字符串pdfPath = Server.MapPath(〜/SomePDFFile.pdf");
WebClient客户端=新的WebClient();
Byte [] buffer = client.DownloadData(pdfPath);
Response.ContentType =应用程序/pdf";
Response.AddHeader("content-length",buffer.Length.ToString());
Response.BinaryWrite(buffer);

2)
Response.Redirect(〜/somePDFFile.pdf");

祝你好运
快乐编码
Hi using two way u can show pdf on web Form

1)
using System.Net;

string pdfPath = Server.MapPath("~/SomePDFFile.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(pdfPath);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);

2)
Response.Redirect("~/somePDFFile.pdf");

Best Luck
happy Coding