Download Pdf file

G

Guest

I am trying to use the below source codes in ASP.NET application to download pdf file
===========================================================================
Response.Clear()
Response.AddHeader("content-disposition", @"attachment; filename=" + strFilenm + "")
Response.ContentType = application/pdf
Response.OutputStream.Write(btDownload,0,btDownload.Length-1);
Response.End()
===========================================================================
However, after i click the "Save" button, the "document" object which i have used in my javascript seems throws a run-time exception. When the Download windows pop up after executing the above source codes, if i click "Cancel" or "Open" buttons, there is no problem, problem only occurs when i click "Save" Button. For your information, when i tried the same application in Netscape 7.1, there is totally no problems at all. Please advice, thanks ...
 
J

Joerg Jooss

Machi said:
I am trying to use the below source codes in ASP.NET application to
download pdf file.
============================================================================
Response.Clear();
Response.AddHeader("content-disposition", @"attachment; filename=" +
strFilenm + "");
Response.ContentType = application/pdf;
Response.OutputStream.Write(btDownload,0,btDownload.Length-1);
Response.End();
============================================================================
However, after i click the "Save" button, the "document" object which
i have used in my javascript seems throws a run-time exception. When
the Download windows pop up after executing the above source codes,
if i click "Cancel" or "Open" buttons, there is no problem, problem
only occurs when i click "Save" Button. For your information, when i
tried the same application in Netscape 7.1, there is totally no
problems at all. Please advice, thanks ...

Response.OutputStream.Write(btDownload,0,btDownload.Length-1) is most likely
wrong. The third parameter passed to Write() is the amount of bytes to be
written, not the end index of the byte array passed as 1st parameter. Use
Response.OutputStream.Write(btDownload,0,btDownload.Length)
instead.

Most versions of the Adobe Acrobat plugin require you to specify a
Content-Length header in the HTTP response. Thus, add
Reponse.AppendHeader("Cotent-Length", btDownload.Length);

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top