473,394 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
2 4138
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jocelyn Duhaylungsod | last post by:
I have been getting the following server errors sporadically while downloading excel, csv or xml file. Internet Explorer cannot download <file name> from <IP address> "The server returned an...
8
by: Scott C. Reynolds | last post by:
I want to serve a PDF right to a web page (cannot link browser directly to PDF file). Stumbled across Response.WriteFile this morning. On my machine (XP Pro) this worked fine: private void...
1
by: Grant Merwitz | last post by:
Hi I am currently using the Response.WriteFile, to write a pdf file to a web browser. This method is working fine and helping me secure the files i need to. However, when a new window is...
0
by: brian.fairchild | last post by:
I have a downloader page in my asp.net application that looks at a session variable to get the path to the file, checks it then downloads it using the Response object. When the "File Download"...
1
by: Ryan Pedersen | last post by:
I have been trying to figure out how to transmit a file back to a user using the response.transmitfile or response.writefile method and just not having much success. I have a dell server running...
1
by: David Union | last post by:
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()...
1
by: ChristopherABurns | last post by:
I have a very simple code snippet here: private void Page_Load(object sender, System.EventArgs e) { string filePath = Server.MapPath("\\Transcriber\\TranscriberTest\\"); string fileName =...
3
by: Dave Keen | last post by:
Hi all. Hope you can help me. This should be easy but I can't make this work. In brief I am building a page of thumbnails using images held in a SQLServer 2000 database. I do this by creating...
3
by: MJP | last post by:
I have a button which kicks off the generation of a report after which the file will be downloaded. The report generation can take a long time, so client side onclick event of the button also...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.