Download Pdf file

  • Thread starter Thread starter Guest
  • Start date Start date
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 ...
 
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,
 
Back
Top