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
After this session the project has been created, A new window is opened on the right side. This window is called the Solution Explorer. Solution Explorer contains the pdf file, css file and aspx files and looks like this:

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, 11:51 AM
How to disable print and download options from the viewer
oohadevi bedapudiPosted Jun 26, 2019, 4:43 AM
How to view pdf fetching from computer using iframe in asp.net plzz help
ahmed shehabPosted May 18, 2019, 9:43 AM
I want to save pdf into database and show it as book flash asp.net web page
Sameh AwwadPosted Aug 10, 2018, 5:33 AM
That is fantastic, i searched for something like this for almost 3 days. Thank you so much
Pramod PeyyalaPosted Aug 10, 2018, 1:08 AM
I want to download pdf insted of open ?
Pardeep BhardwajPosted May 22, 2018, 1:09 AM
How to open pdf file in view in mvc .net
Shubham AgrawalPosted Oct 14, 2017, 1:02 AM
But i want To open Pdf in new Tab.So plz Give Reply for that.
NAIMESH SUTHARPosted May 22, 2017, 2:21 PM
How to open this pdf in new window
Saktiprasad SwainPosted Jun 15, 2016, 4:23 AM
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 8, 2015, 2:51 AM
But I get some issue in this process..File not opening...but always asking for download..
vipul patilPosted May 25, 2015, 9:46 AM
Working fine on Chrome but on IE it download PDF file instead of displaying, Is there any solution ?
Former memberPosted May 4, 2015, 4:44 AM
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, 4:05 AM
can you help me open pdf file in web browser in silverlight please
Sergio Martínez SeguraPosted Nov 2, 2014, 9:17 AM
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, 8:45 AM
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, 5:07 AM
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, 4:04 PM
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.