That worked beautifully, when the method was called from an asp.net
button click. Now it has to be called from a javascript menu system,
so I've put the method on the OnPageLoad handler.
Response.End doesn't work anymore; I get a "Thread was being aborted"
exception. Even though I put it right at the end of my asp.net method,
there is some javascript that runs after the method returns, and I
assume that this is what is interfering with Response.End.
Is there any other way to do this?
Chris Botha wrote:
> After Response.BinaryWrite add the statement
> Response.End()
>
> "Cathryn Johns" <> wrote in message
> news: oups.com...
> > Hi
> >
> > I'm trying to download some content as a file to the client. My code
> > behind looks like this:
> >
> > private void DownloadFile(byte[] contents)
> > {
> > Response.ContentType = "text/csv";
> > Response.AppendHeader("content-disposition",
> > "attachment;filename=myFile.csv");
> > Response.AppendHeader("content-length",contents.Length.ToString());
> > Response.BinaryWrite(contents);
> > }
> >
> > It works to an extent, in that it pops up the file download dialog and
> > writes a file to the user's selected path. But the problem is what's
> > being written: the first part of the file is the byte array that I'm
> > trying to write, but the rest is my page's html (see below for sample
> > output). I thought that setting the content-length header to the
> > length of the byte array would force it to only write that many bytes,
> > but it still writes 1.12Kb regardless.
> >
> > I just don't know what else to try; any ideas would be appreciated.
> >
> > Sample output (the HIPQ is the contents of the byte array):
> > HIPQ
> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> > <HTML>
> > <HEAD>
> > <title>ViewAllocations</title>
> >
> > .
> > .
> > .
> > etc.
> >
|