Gregory Silvano
2003-12-22 11:08:19 PM

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

 

Re: .NET Bug with BinaryWrite or just bad code?

Gregory Silvano
2003-12-22 11:17:00 PM

Sorry, forgot to mention that this uses version 1.0 of the .NET
Framework with SP1 installed.

Thanks...
 



Re: .NET Bug with BinaryWrite or just bad code?

Patrice Scribe
2003-12-23 12:10:00 AM

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:5c1euv4ls6os9u87p6suu7cfl6mkf6tov8@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
>

 



Re: .NET Bug with BinaryWrite or just bad code?

George Ter-Saakov
2003-12-23 04:47:00 AM

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:5c1euv4ls6os9u87p6suu7cfl6mkf6tov8@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
>


 



Re: .NET Bug with BinaryWrite or just bad code?

Gregory Silvano
2003-12-23 11:56:00 PM

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"
<nobody@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

 



Re: .NET Bug with BinaryWrite or just bad code?

Gregory Silvano
2003-12-23 11:57:00 PM

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"
<nospam@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:5c1euv4ls6os9u87p6suu7cfl6mkf6tov8@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
>>
>