By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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)

--
Joe Fallon


"David Union" <d.*****@verizon.net> wrote in message
news:uW***************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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.

..
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)

--
Joe Fallon


"David Union" <d.*****@verizon.net> wrote in message
news:uW***************@TK2MSFTNGP11.phx.gbl...
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


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.