473,467 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

.NET Bug with BinaryWrite or just bad code?

I have reproduced this problem on several machines (all different
configs) and don't see anything wrong with the code. The code below
(or very similar) is from Microsoft (help files, newsgroup posts,
etc.) and available at several other resources on the Web.

If you click on the LinkButton once or twice it works without
problems. However, on the third (sometimes the second) click the
browser hangs. It never even gets to a breakpoint in the PageLoad
event. Sometimes it'll just spit out the gif binary code in the page,
floating above the existing browser page like a watermark. Weird.

Can somebody reproduce this behavior?

Just create a WebApplication and throw a LinkButton on the page,
keeping the default name. Put the code below in the codebehind and
throw a gif or something in the same directory as your web form,
calling it test.gif.
Private Sub LinkButton1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LinkButton1.Click

Dim MyFileStream As System.IO.FileStream = New _
System.IO.FileStream(Server.MapPath("test.gif"), _
System.IO.FileMode.Open)

'Get the file length
Dim FileSize As Integer = MyFileStream.Length

'Read the file into the buffer and close the file stream
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

'I've also tried Response.Clear and .ClearContents
Response.ClearHeaders()

Response.ContentType = "application/octet-stream"

'We want to force a download
Response.AddHeader("Content-Disposition", _
"attachment; filename=test123.gif")
Response.AddHeader("Content-Length", FileSize)

Response.BinaryWrite(Buffer)

End Sub
I appreciate any insight you may have. I have been having problems
getting WriteFile to work in SSL, so that's why I'm using the
BinaryWrite approach. Thanks...
Regards,

Gregory Silvano

Nov 18 '05 #1
5 1716
Sorry, forgot to mention that this uses version 1.0 of the .NET
Framework with SP1 installed.

Thanks...
Nov 18 '05 #2
Looks even a bit weird you can click several times. My first try would be to
see how it behaves when writing the gif file in a new window.

Also I would start with just the content-disposition header (in particular
doesn't clear the header, doesn't use the content length and the content
type for now, is it enough to still work ? does it still hang ?).
Patrice
--

"Gregory Silvano" <g.s.i.l.v.a.n.o(delete_the_dots)@codehound.com> a écrit
dans le message de news:5c********************************@4ax.com...
I have reproduced this problem on several machines (all different
configs) and don't see anything wrong with the code. The code below
(or very similar) is from Microsoft (help files, newsgroup posts,
etc.) and available at several other resources on the Web.

If you click on the LinkButton once or twice it works without
problems. However, on the third (sometimes the second) click the
browser hangs. It never even gets to a breakpoint in the PageLoad
event. Sometimes it'll just spit out the gif binary code in the page,
floating above the existing browser page like a watermark. Weird.

Can somebody reproduce this behavior?

Just create a WebApplication and throw a LinkButton on the page,
keeping the default name. Put the code below in the codebehind and
throw a gif or something in the same directory as your web form,
calling it test.gif.
Private Sub LinkButton1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LinkButton1.Click

Dim MyFileStream As System.IO.FileStream = New _
System.IO.FileStream(Server.MapPath("test.gif"), _
System.IO.FileMode.Open)

'Get the file length
Dim FileSize As Integer = MyFileStream.Length

'Read the file into the buffer and close the file stream
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

'I've also tried Response.Clear and .ClearContents
Response.ClearHeaders()

Response.ContentType = "application/octet-stream"

'We want to force a download
Response.AddHeader("Content-Disposition", _
"attachment; filename=test123.gif")
Response.AddHeader("Content-Length", FileSize)

Response.BinaryWrite(Buffer)

End Sub
I appreciate any insight you may have. I have been having problems
getting WriteFile to work in SSL, so that's why I'm using the
BinaryWrite approach. Thanks...
Regards,

Gregory Silvano


Nov 18 '05 #3
I would add Response.End right after Response.BinaryWrite

George.
"Gregory Silvano" <g.s.i.l.v.a.n.o(delete_the_dots)@codehound.com> wrote in
message news:5c********************************@4ax.com...
I have reproduced this problem on several machines (all different
configs) and don't see anything wrong with the code. The code below
(or very similar) is from Microsoft (help files, newsgroup posts,
etc.) and available at several other resources on the Web.

If you click on the LinkButton once or twice it works without
problems. However, on the third (sometimes the second) click the
browser hangs. It never even gets to a breakpoint in the PageLoad
event. Sometimes it'll just spit out the gif binary code in the page,
floating above the existing browser page like a watermark. Weird.

Can somebody reproduce this behavior?

Just create a WebApplication and throw a LinkButton on the page,
keeping the default name. Put the code below in the codebehind and
throw a gif or something in the same directory as your web form,
calling it test.gif.
Private Sub LinkButton1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LinkButton1.Click

Dim MyFileStream As System.IO.FileStream = New _
System.IO.FileStream(Server.MapPath("test.gif"), _
System.IO.FileMode.Open)

'Get the file length
Dim FileSize As Integer = MyFileStream.Length

'Read the file into the buffer and close the file stream
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

'I've also tried Response.Clear and .ClearContents
Response.ClearHeaders()

Response.ContentType = "application/octet-stream"

'We want to force a download
Response.AddHeader("Content-Disposition", _
"attachment; filename=test123.gif")
Response.AddHeader("Content-Length", FileSize)

Response.BinaryWrite(Buffer)

End Sub
I appreciate any insight you may have. I have been having problems
getting WriteFile to work in SSL, so that's why I'm using the
BinaryWrite approach. Thanks...
Regards,

Gregory Silvano

Nov 18 '05 #4
Patrice,

Thank you - it was the Content-Length that caused it to blow up.

I also needed the Response.End after the BinaryWrite, or the
downloaded file would contain all the HTML of the page appended to the
end of it.

Thanks for taking the time to help...
Greg

On Mon, 22 Dec 2003 17:10:20 +0100, "Patrice Scribe"
<no****@nowhere.com> wrote:
Looks even a bit weird you can click several times. My first try would be to
see how it behaves when writing the gif file in a new window.

Also I would start with just the content-disposition header (in particular
doesn't clear the header, doesn't use the content length and the content
type for now, is it enough to still work ? does it still hang ?).
Patrice


Nov 18 '05 #5
Thanks George,

While Response.End didn't solve the initial problem, it did solve the
issue that every downloaded file contained the page's HTML appended to
the end of it.
Greg

On Mon, 22 Dec 2003 15:47:20 -0500, "George Ter-Saakov"
<no****@hotmail.com> wrote:
I would add Response.End right after Response.BinaryWrite

George.
"Gregory Silvano" <g.s.i.l.v.a.n.o(delete_the_dots)@codehound.com> wrote in
message news:5c********************************@4ax.com...
I have reproduced this problem on several machines (all different
configs) and don't see anything wrong with the code. The code below
(or very similar) is from Microsoft (help files, newsgroup posts,
etc.) and available at several other resources on the Web.

If you click on the LinkButton once or twice it works without
problems. However, on the third (sometimes the second) click the
browser hangs. It never even gets to a breakpoint in the PageLoad
event. Sometimes it'll just spit out the gif binary code in the page,
floating above the existing browser page like a watermark. Weird.

Can somebody reproduce this behavior?

Just create a WebApplication and throw a LinkButton on the page,
keeping the default name. Put the code below in the codebehind and
throw a gif or something in the same directory as your web form,
calling it test.gif.
Private Sub LinkButton1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LinkButton1.Click

Dim MyFileStream As System.IO.FileStream = New _
System.IO.FileStream(Server.MapPath("test.gif"), _
System.IO.FileMode.Open)

'Get the file length
Dim FileSize As Integer = MyFileStream.Length

'Read the file into the buffer and close the file stream
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

'I've also tried Response.Clear and .ClearContents
Response.ClearHeaders()

Response.ContentType = "application/octet-stream"

'We want to force a download
Response.AddHeader("Content-Disposition", _
"attachment; filename=test123.gif")
Response.AddHeader("Content-Length", FileSize)

Response.BinaryWrite(Buffer)

End Sub
I appreciate any insight you may have. I have been having problems
getting WriteFile to work in SSL, so that's why I'm using the
BinaryWrite approach. Thanks...
Regards,

Gregory Silvano


Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jens S0nderby Munk | last post by:
Hi, I'm having some problems with the Reponse.BinaryWrite, IE 6.0 and Adobe Reader 6.0. When I try to write a pdf-file to an IE browser with a Adobe Reader 6.0 installed then it just displays a...
2
by: Nik | last post by:
I am trying to write out the equivalent of this asp statement in c#: Response.BinaryWrite(chrb(239) & chrb(187) & chrb(191)) 'BOM = EF BB BF string binString = "11111111"; byte myBin =...
11
by: Random | last post by:
I have tried all the Response methods I can think of (WriteFile, BinaryWrite, OutputStream) to write the byte array of a pdf file to the response. The result looks like it's trying, it comes up as...
14
by: S N | last post by:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client. Kindly indicate the maximum size of the file that can be...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.