Force Download PDF Problem

Discussion in 'ASP .Net' started by gaubo79, Dec 20, 2005.

  1. gaubo79

    gaubo79 Guest

    I am wishing to force the Open|Save dialog box for a PDF and Excel
    file.

    I am using the following code:

    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" +
    saveFilename );
    Response.Flush();
    Response.WriteFile(savePath);

    While this works perfect for the Excel file, however, the PDF file does
    not open, whether direct from the dialog box or by saving it to disk
    and opening it, I get the following error in Adobe Acrobat Reader (v5.0
    & v7.0):

    "There was an error opening this document. The file is damaged and
    could not be repaired."

    The original PDF file is okay. Also, the size of the original PDF is
    50k, where as the one that is downloaded to the client is 237k.

    I have tried various other things such as creating a FileStream and
    using Response.BinaryWrite, and various other ContentTypes, including
    application/pdf.

    Has anyone had this before, or know of a workaround? Ideally I would
    like the dialog box to always appear for this pdf.
     
    gaubo79, Dec 20, 2005
    #1
    1. Advertising

  2. gaubo79

    RCS Guest

    I know you're looking for something helpful - but I can say, that looks 100%
    correct.. so if nothing else, it doesn't appear to be anything obvious. Good
    luck

    "gaubo79" <> wrote in message
    news:...
    >I am wishing to force the Open|Save dialog box for a PDF and Excel
    > file.
    >
    > I am using the following code:
    >
    > Response.Clear();
    > Response.ContentType = "application/octet-stream";
    > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    > saveFilename );
    > Response.Flush();
    > Response.WriteFile(savePath);
    >
    > While this works perfect for the Excel file, however, the PDF file does
    > not open, whether direct from the dialog box or by saving it to disk
    > and opening it, I get the following error in Adobe Acrobat Reader (v5.0
    > & v7.0):
    >
    > "There was an error opening this document. The file is damaged and
    > could not be repaired."
    >
    > The original PDF file is okay. Also, the size of the original PDF is
    > 50k, where as the one that is downloaded to the client is 237k.
    >
    > I have tried various other things such as creating a FileStream and
    > using Response.BinaryWrite, and various other ContentTypes, including
    > application/pdf.
    >
    > Has anyone had this before, or know of a workaround? Ideally I would
    > like the dialog box to always appear for this pdf.
    >
     
    RCS, Dec 20, 2005
    #2
    1. Advertising

  3. 1) Use ClearHeaders() and ClearContents() CH is imo important for
    authentication issues.
    2) Response.End really seems to flush, Response.Flush seems not enough.
    3) Not using Response.end seems to be a problem on localhost only so far.

    I ran across the R.E issue yesterday,.
    Odd, i was trying to avoid this end.



    "RCS" <> schreef in bericht
    news:AIWpf.4206$...
    >I know you're looking for something helpful - but I can say, that looks
    >100% correct.. so if nothing else, it doesn't appear to be anything
    >obvious. Good luck
    >
    > "gaubo79" <> wrote in message
    > news:...
    >>I am wishing to force the Open|Save dialog box for a PDF and Excel
    >> file.
    >>
    >> I am using the following code:
    >>
    >> Response.Clear();
    >> Response.ContentType = "application/octet-stream";
    >> Response.AddHeader("Content-Disposition", "attachment; filename=" +
    >> saveFilename );
    >> Response.Flush();
    >> Response.WriteFile(savePath);
    >>
    >> While this works perfect for the Excel file, however, the PDF file does
    >> not open, whether direct from the dialog box or by saving it to disk
    >> and opening it, I get the following error in Adobe Acrobat Reader (v5.0
    >> & v7.0):
    >>
    >> "There was an error opening this document. The file is damaged and
    >> could not be repaired."
    >>
    >> The original PDF file is okay. Also, the size of the original PDF is
    >> 50k, where as the one that is downloaded to the client is 237k.
    >>
    >> I have tried various other things such as creating a FileStream and
    >> using Response.BinaryWrite, and various other ContentTypes, including
    >> application/pdf.
    >>
    >> Has anyone had this before, or know of a workaround? Ideally I would
    >> like the dialog box to always appear for this pdf.
    >>

    >
    >
     
    Edwin Knoppert, Dec 20, 2005
    #3
  4. gaubo79

    Joey Guest

    If, by some chance, you have entered an IIS->asp.net mapping for PDF
    documents, delete it. The problem will go away. This happened to me
    when I tried to add a mapping so as to allow for asp.net to control
    security on PDF documents.

    gaubo79 wrote:
    > I am wishing to force the Open|Save dialog box for a PDF and Excel
    > file.
    >
    > I am using the following code:
    >
    > Response.Clear();
    > Response.ContentType = "application/octet-stream";
    > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    > saveFilename );
    > Response.Flush();
    > Response.WriteFile(savePath);
    >
    > While this works perfect for the Excel file, however, the PDF file does
    > not open, whether direct from the dialog box or by saving it to disk
    > and opening it, I get the following error in Adobe Acrobat Reader (v5.0
    > & v7.0):
    >
    > "There was an error opening this document. The file is damaged and
    > could not be repaired."
    >
    > The original PDF file is okay. Also, the size of the original PDF is
    > 50k, where as the one that is downloaded to the client is 237k.
    >
    > I have tried various other things such as creating a FileStream and
    > using Response.BinaryWrite, and various other ContentTypes, including
    > application/pdf.
    >
    > Has anyone had this before, or know of a workaround? Ideally I would
    > like the dialog box to always appear for this pdf.
     
    Joey, Dec 20, 2005
    #4
  5. gaubo79

    gaubo79 Guest

    Joey,

    I certainly haven't entered one, is there anyway it could be there by
    default?

    I had a look through IIS manager, but couldn't find anything, where
    would it be if it was in place?

    Thanks

    Joey wrote:

    > If, by some chance, you have entered an IIS->asp.net mapping for PDF
    > documents, delete it. The problem will go away. This happened to me
    > when I tried to add a mapping so as to allow for asp.net to control
    > security on PDF documents.
    >
    > gaubo79 wrote:
    > > I am wishing to force the Open|Save dialog box for a PDF and Excel
    > > file.
    > >
    > > I am using the following code:
    > >
    > > Response.Clear();
    > > Response.ContentType = "application/octet-stream";
    > > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    > > saveFilename );
    > > Response.Flush();
    > > Response.WriteFile(savePath);
    > >
    > > While this works perfect for the Excel file, however, the PDF file does
    > > not open, whether direct from the dialog box or by saving it to disk
    > > and opening it, I get the following error in Adobe Acrobat Reader (v5.0
    > > & v7.0):
    > >
    > > "There was an error opening this document. The file is damaged and
    > > could not be repaired."
    > >
    > > The original PDF file is okay. Also, the size of the original PDF is
    > > 50k, where as the one that is downloaded to the client is 237k.
    > >
    > > I have tried various other things such as creating a FileStream and
    > > using Response.BinaryWrite, and various other ContentTypes, including
    > > application/pdf.
    > >
    > > Has anyone had this before, or know of a workaround? Ideally I would
    > > like the dialog box to always appear for this pdf.
     
    gaubo79, Dec 21, 2005
    #5
  6. gaubo79

    gaubo79 Guest

    Response.ClearHeaders();
    Response.ClearContent();
    Response.ContentType="application/octet-stream";
    Response.AddHeader("content-disposition","attachment; filename=" +
    saveFilename);
    Response.WriteFile(savePath);
    Response.End();

    This works fine, many thanks.
     
    gaubo79, Dec 21, 2005
    #6
  7. gaubo79

    giridhar86

    Joined:
    May 19, 2011
    Messages:
    1
    This works fine, many many many thanks so nice of you . :D:D :D:D:D [/QUOTE]
     
    giridhar86, May 19, 2011
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    486
    =?Utf-8?B?bGF0aGEgdmFsbGluYXlhZ2Ft?=
    May 5, 2005
  2. NUG-IT
    Replies:
    11
    Views:
    2,017
  3. Don Grover

    Force download of pdf file

    Don Grover, Feb 5, 2004, in forum: ASP General
    Replies:
    4
    Views:
    172
    Ray at
    Feb 6, 2004
  4. Ricardo Pog
    Replies:
    1
    Views:
    454
    Austin Ziegler
    Mar 26, 2008
  5. Cylix
    Replies:
    1
    Views:
    109
    Randy Webb
    Aug 21, 2006
Loading...

Share This Page