File download problem - content-disposition as attachment breaks p

Discussion in 'ASP .Net' started by =?Utf-8?B?R1JF?=, Aug 19, 2004.

  1. I'm hoping someone can help with this problem; I've seen only a handful of
    postings related to it, but with no clear resolution.

    I have an ASP.NET 1.1 page that downloads requested files via the
    "Response.BinaryWrite(...)" method. The problem is that the page is
    dynamically built, and after the download completes all javascript functions
    suddenly break or exhibit unpredictable behavior.

    I've traced the issue down the use of the "attachment" attribute when
    setting the Content-Disposition header. For example:

    Reponse.AppendHeader("content-disposition", "attachment;
    filename=testfile.txt");

    .... will download the file intact, but the page will lose all of its
    javascript references.
    I'm also adding the obligatory "Response.End()" statement after the last
    "Response.Flush()".

    One odd note is that omitting the "attachment" attribute altogether will
    allow for some files to download and NOT break the page afterwards. However,
    this is not reliable for types that could be rendered to the browser (.txt,
    etc.).

    Has anyone else come across this problem, and is there any consensus on what
    might be causing it? Any feedback, resources, etc., here would be greatly
    appreciated.

    GRE
    =?Utf-8?B?R1JF?=, Aug 19, 2004
    #1
    1. Advertising

  2. Re: File download problem - content-disposition as attachment breaksp

    On 8/19/2004 4:17 PM, GRE wrote:

    > I'm hoping someone can help with this problem; I've seen only a handful of
    > postings related to it, but with no clear resolution.
    >
    > I have an ASP.NET 1.1 page that downloads requested files via the
    > "Response.BinaryWrite(...)" method. The problem is that the page is
    > dynamically built, and after the download completes all javascript functions
    > suddenly break or exhibit unpredictable behavior.
    >
    > I've traced the issue down the use of the "attachment" attribute when
    > setting the Content-Disposition header. For example:
    >
    > Reponse.AppendHeader("content-disposition", "attachment;
    > filename=testfile.txt");
    >
    > ... will download the file intact, but the page will lose all of its
    > javascript references.
    > I'm also adding the obligatory "Response.End()" statement after the last
    > "Response.Flush()".
    >
    > One odd note is that omitting the "attachment" attribute altogether will
    > allow for some files to download and NOT break the page afterwards. However,
    > this is not reliable for types that could be rendered to the browser (.txt,
    > etc.).
    >
    > Has anyone else come across this problem, and is there any consensus on what
    > might be causing it? Any feedback, resources, etc., here would be greatly
    > appreciated.
    >
    > GRE

    Hmmm, are you saying you want to have some Javascript in the browser, in
    the same page/frame that is writing the file out? That can't happen,
    you can't mix MIME types; either you are writing HTML to the browser, or
    sending the attachment in 1 response...Are you using frames, or what is
    the page layout here?

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Aug 20, 2004
    #2
    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. ben
    Replies:
    0
    Views:
    1,064
  2. Costas Andriotis
    Replies:
    0
    Views:
    1,147
    Costas Andriotis
    Oct 15, 2004
  3. Sergio Juan
    Replies:
    1
    Views:
    1,021
    mohammad.h.ashmawi
    Apr 29, 2011
  4. Replies:
    1
    Views:
    763
  5. Ed
    Replies:
    10
    Views:
    45,873
    alok000707
    Jul 13, 2010
Loading...

Share This Page