TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Open PDF File in ASP.NET
Pintoo Yadav
Jan 16
2015
Code
1.7
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
Open_PDF_Using_ASP.N
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"Open_PDF.aspx.cs"
Inherits=
"Open_PDF"
%>
<!DOCTYPE html>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head runat=
"server"
>
<title></title>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<h3 style=
"color: #0000FF"
>Open PDF files using ASP.NET</h3>
<div>
<asp:Button ID=
"bttnpdf"
runat=
"server"
Text=
"Click for open PDF"
Font-Bold=
"True"
OnClick=
"bttnpdf_Click"
/>
</div>
</form>
</body>
</html>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Net;
public
partial
class
Open_PDF : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
bttnpdf_Click(
object
sender, EventArgs e)
{
string
FilePath = Server.MapPath(
"javascript1-sample.pdf"
);
WebClient User =
new
WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if
(FileBuffer !=
null
)
{
Response.ContentType =
"application/pdf"
;
Response.AddHeader(
"content-length"
, FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
}
}
ASP.NET
PDF
Open PDF File in ASP.NET