DownLoad Pdf file in Asp.net 2.0

1) Create the Simple Web Application.

2) Now add the new folder (FolderName : PDFFile).

2.1) right click on the project and add folder.

3) put the one pdf file in to folder ( name :1.pdf).

4) in the web page put the control

4.1) put the button control (name : btnPdfFiledownload)

(note: Here we use hardcoded thing (means use button control and path)

if you want to change then you do it.)

5) on the button click (means btnPdfFiledownload) you write the below code.

protected void btnPdfFiledownload_Click(object sender, EventArgs e)

{

//get the physical path of your drive + append the folder and you file name with this

//example my folder is on the same level of this (foldername ->PDFFile)

//file name is 1.pdf

string strMapPath = Server.MapPath(Request.Url.AbsolutePath.Substring(0, Request.Url.AbsolutePath.LastIndexOf(“//”) + 1)) + @”\PDFFile\1.pdf”;

//enter the content type (describe the pdf)

Response.ContentType = “application/pdf”;

//in the filename you can give whatever you want

//when download the file at that save this file with this filename

//Adds an HTTP header to the output stream.

Response.AppendHeader(“Content-Disposition”, “attachment; filename=applicationfile.pdf”);

//TransmitFile do –> Writes the specified file directly to an HTTP response output stream without buffering it in memory

Response.TransmitFile(strMapPath);

//End Response

Response.End();

}

Thank you.


http://amitpatriwala.blogspot.com/

Advertisements

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