Response.WriteFile() giving an extra byte at the end?

D

David Union

Hi.
I'm posting this here because I don't know exactly what the best group is.
This is for an aspx page with Visual Basic as the code-behind page.

I am doing very simple code...
in the middle of an http request, i set a filename (with path)
and do a Response.WriteFile(filenamewithpath)
then Response.End().

I have tried Response.Clear() and .Flush() ahead of time.

I have tried various permutations (all, I think) of Content-Type
and Content-Disposition.

I have also tried opening a file stream and copying the data
to an array of bytes (the data is good in the array) and then
doing a Response.BinaryWrite(binaryarray)
then Response.End().

I've also tried Response.Close().

In all cases I get an extra byte at the end of the file,
so the CRC doesn't match up.

Anyone know the solution for this?

Windows 2000 Server, Visual Studio 2003
with the appropriate and updated framework.

Thanks,
DU
 
J

Joe Fallon

These are the key steps in my download function:

Response.Clear()
Response.ContentType = "text/plain"

'Used to force the Browser to show the Save As dialog box.
Response.AppendHeader("Content-Disposition", "attachment; filename=""" &
filename & """")

'Stop ASP.Net from adding the HTML of the host .aspx file to the end of the
downloaded file.
Response.AppendHeader("Content-Length", fileSize.ToString)

Response.Flush()
Response.WriteFile(filepath)
 
D

David Union

I had tried this, still got the junk.
I got it to work with the following and It's not clear why I needed it

Response.Buffer = true ' I wanted false, no buffering

I did Content-Disposition as inline; filename= ..
I did set the type as octet-stream.
I did the Response.Clear()

I did not do the flush first
I did the response.writefile(filename)
I then did a flush.

I don't know why that isn't the same as
doing something like

Respose.Buffer = false
Response.WriteFile(filename)
Response.End().

The end causes an exception cutting off the write before it's finished
and the response gets a lot of crap then posted on to it, or if it
gets the data in time, just the extra byte.

..
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top