Hi friends, in this article I will explain about How to open PDF File in Adobe Reader, not in Browser in ASP.NET using C#/VB.NET.
I already explained in the previous articles about How to create PDF document in ASP.NET with C#/VB.NET using iTextSharp, Create/Generat PDF with image Using RazorPDF in ASP.Net MVC and How to Export Gridview data to PDF File in ASP.NET using C#/VB.NET
In ASP.NET:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> How to
open PDF File in Adobe Reader, not in Browser in ASP.NET using C#/VB.NET</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtFile" runat="server"></asp:TextBox>
<asp:Button ID="btnPDF" runat
="server" onclick="btnPDF_Click" Text ="Show PDF File"/>
</div>
</form>
</body>
</html>
|
In
C#:
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Net;
using System.Diagnostics;
public partial class ShowPDF : System.Web.UI.Page
{
protected
void btnPDF_Click(object
sender, EventArgs e)
{
Document document = new
Document();
String appPath =
Context.Request.PhysicalApplicationPath + "PDF\\";
String fileName = txtFile.Text.ToString() + ".pdf";
String FilePath = appPath + fileName;
ReadPdfFile(FilePath);
}
private
void ReadPdfFile(string
FilePath)
{
WebClient client = new
WebClient();
Byte[] buffer = client.DownloadData(FilePath);
Process.Start(FilePath);
}
}
|
In VB.NET:
Imports
System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports
System.Web.UI.WebControls
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports System.Net
Imports System.Diagnostics
Partial Public Class ShowPDF
Inherits
System.Web.UI.Page
Protected
Sub btnPDF_Click(sender As Object, e As EventArgs)
Dim document As New Document()
Dim appPath As [String] =
Context.Request.PhysicalApplicationPath + "PDF\"
Dim fileName As [String] = txtFile.Text.ToString() + ".pdf"
Dim FilePath As [String] = appPath + fileName
ReadPdfFile(FilePath)
End
Sub
Private
Sub ReadPdfFile(FilePath As String)
Dim client As New WebClient()
Dim buffer As [Byte]() = client.DownloadData(FilePath)
Process.Start(FilePath)
End
Sub
End Class
|
No comments:
Post a Comment