In this article I will explain with an example, how to open (view) PDF files without using IFRAME in ASP.Net using C# and VB.Net.
This article will explain how to view PDF files directly within browser without downloading them.
 
 
HTML Markup
The HTML Markup consists of an ASP.Net LinkButton and a Literal control.
<asp:LinkButton ID="lnkView" runat="server" Text="View PDF" OnClick="View"></asp:LinkButton>
<hr />
<asp:Literal ID="ltEmbed" runat="server" />
 
 
Display PDF file without using IFRAME in ASP.Net
The below event handler is raised when the View LinkButton is clicked. Here I am making use of HTML OBJECT Tag to embed PDF in browser. An HTML string of an OBJECT tag is generated in which the path of the PDF file is set.
The HTML string is then set to the Literal Tag.
To know more about Literal control, please visit Difference between Label and Literal control in ASP.Net.
 
C#
protected void View(object sender, EventArgs e)
{
    string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"500px\" height=\"300px\">";
    embed += "If you are unable to view file, you can download from <a href = \"{0}\">here</a>";
    embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
    embed += "</object>";
    ltEmbed.Text = string.Format(embed, ResolveUrl("~/Files/Mudassar_Khan.pdf"));
}
 
VB.Net
Protected Sub View(sender As Object, e As EventArgs)
    Dim embed As String = "<object data=""{0}"" type=""application/pdf"" width=""500px"" height=""300px"">"
    embed += "If you are unable to view file, you can download from <a href = ""{0}"">here</a>"
    embed += " or download <a target = ""_blank"" href = ""http://get.adobe.com/reader/"">Adobe PDF Reader</a> to view the file."
    embed += "</object>"
    ltEmbed.Text = String.Format(embed, ResolveUrl("~/Files/Mudassar_Khan.pdf"))
End Sub
 
 
Screenshots
Adobe PDF Reader installed
Display PDF file without using IFRAME in ASP.Net
Adobe PDF Reader not installed
Display PDF file without using IFRAME in ASP.Net
 
Demo
 
 
Downloads