468,784 Members | 1,564 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,784 developers. It's quick & easy.

File download problem - content-disposition as attachment breaks p

GRE
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
Nov 18 '05 #1
1 2122
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
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by BOHICA | last post: by
6 posts views Thread by Bryan Martin | last post: by
1 post views Thread by Chameleon | last post: by
3 posts views Thread by rafi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.