Introduction
In this article, I will explain how to open a PDF file in a web browser using ASP.NET.
Use the following procedure.
Step 1
Open Visual Studio 2012 and click "File" -> "New" -> "web site...". A window is opened. In this window, click "Empty Web Site Application" under Visual C#.

Give the name of your application as "Open_PDF" and then click "Ok".
Step 2

Complete Program
CreateZip.aspx
<%@ 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>Open.aspx.cs
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);
}
}
}Output

Click on the button.

For more information, download the attached sample application.


rajkumar ganesanPosted Jan 21, 2020, 6:51 AM EST
How to disable print and download options from the viewer
oohadevi bedapudiPosted Jun 26, 2019, 12:43 AM EDT
How to view pdf fetching from computer using iframe in asp.net plzz help
ahmed shehabPosted May 18, 2019, 5:43 AM EDT
I want to save pdf into database and show it as book flash asp.net web page
Sameh AwwadPosted Aug 10, 2018, 1:33 AM EDT
That is fantastic, i searched for something like this for almost 3 days. Thank you so much
Pramod PeyyalaPosted Aug 9, 2018, 9:08 PM EDT
I want to download pdf insted of open ?
Pardeep BhardwajPosted May 21, 2018, 9:09 PM EDT
How to open pdf file in view in mvc .net
Shubham AgrawalPosted Oct 13, 2017, 9:02 PM EDT
But i want To open Pdf in new Tab.So plz Give Reply for that.
NAIMESH SUTHARPosted May 22, 2017, 10:21 AM EDT
How to open this pdf in new window
Saktiprasad SwainPosted Jun 15, 2016, 12:23 AM EDT
I don't know who u r are,Where u live but I m gonna find u and Thanks u for saving my ass.
Mahesh kumawatPosted Jun 7, 2015, 10:51 PM EDT
But I get some issue in this process..File not opening...but always asking for download..
vipul patilPosted May 25, 2015, 5:46 AM EDT
Working fine on Chrome but on IE it download PDF file instead of displaying, Is there any solution ?
Former memberPosted May 4, 2015, 12:44 AM EDT
Nice...I want to open multiple pdf file.Is it possible to open in same code or any other code.
neha thakurPosted Mar 21, 2015, 12:05 AM EDT
can you help me open pdf file in web browser in silverlight please
Sergio Martínez SeguraPosted Nov 2, 2014, 4:17 AM EST
despu?s de varios intentos, lo logre, pero al principio me marca el mismo error que he arrastrado desde hace un buen rato (algo de java), lo que hice es meter tu rutina en un formulario el blanco y agregarla en el load del mimo webform y llamar a este desde la pantalla principal con el respose.write("formulario.aspx") y listo, gracias por el aporte, saludos desde m?xico
Sergio Martínez SeguraPosted Nov 2, 2014, 3:45 AM EST
gracias, intentare esto ya que en todos los tutoriales lo hacen en windows form, adem?s en versiones anteriores a la 2012 si me funcionaba mi rutina, pero tu lo has realizado en 2012, lo voy a checar, saludos desde m?xico
Mukesh Kumar TiwariPosted Jul 11, 2014, 1:07 AM EDT
hey what i should do if my pdf is save in binary format in database... i mean i have store my dpf and image in binary format in database.And nw i want to show both stuff in anther tab of a web browser. Can you help me out..plz
Shaify MehtaPosted May 13, 2013, 12:04 PM EDT
Nice Article but want to know whether your solution is compatible with all browsers and i think acrobat adobe reader must be installed on the client pc in order to open the pdf file.