Wednesday, October 8, 2008

How to download PDF on Button click using asp.net

// html part ...

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Download Filestitle>

head>

<body>

<form id="form1" runat="server">

<div>

<asp:Button ID="Button_Download" runat="server" Text="Download" OnClick="Button_Download_Click" />

div>

form>

body>

html>


// code part ...

protected void Button_Download_Click(object sender, EventArgs e)

{

string str_FilePath = Server.MapPath(".") + @"\UploadedItems\Docs\CV.pdf";

System.IO.StreamReader sr = new System.IO.StreamReader(str_FilePath);

Response.BufferOutput = true;

Response.AppendHeader("content-disposition", "attachment; filename=v.pdf");

Response.ContentType = "application/pdf";

Response.TransmitFile(str_FilePath);

}


-
ShriKrishna Bhardwaj , With ASP.Net, SQL Server, Javascript

1 comment:

Sharad Mahajan said...

this is very use full for me thank you