Display a PDF in an ASP.NET page

It was surprisingly simple to display a PDF file in an ASP.NET page. First, in the .aspx page, I cleared out all the code except for the first line. Here is the complete page:

 <%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”PdfDisplay.aspx.cs” Inherits=”MyProject.PdfDisplay” %>

 In the code-behind file, I added the following to the Page_Load event:

Response.Clear();
string filePath = @”C:\Documents\MyReport.pdf”;
Response.ContentType = “application/pdf”;
Response.WriteFile(filePath);

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: