Why won't my download ever end?

J

Jerry Camel

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
G

George Ter-Saakov

Here is the my theory.
Add ContentLength: to the header.

Response.AppendHeader("ContentLength", Filesize.tostirng() )
Let me know if it worked.
George.



I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
J

Jerry Camel

I appreciate the response, but that didn't do it. I was hoping it would at least address another item I posted regarding download progress, but it didn't do that either. Any other ideas?

Jerry
Here is the my theory.
Add ContentLength: to the header.

Response.AppendHeader("ContentLength", Filesize.tostirng() )
Let me know if it worked.
George.



I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
J

Jerry Camel

FYI - This only seems to be a problem with larger downloads. The smaller downloads work just fine.
I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
E

Earl Teigrob

Jerry,

If you solve this, it will be amazing. I spend days last week researching ths issue and read about developer teams spending months trying to get a solution, and finally did (but in a very messy and complex way). I hope you get it though...we will all be happy!!!

Earl

BTW, with the current solution you have so for, does the dowload dialog pop up to the client right away?

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
E

Eric Lawrence [MSFT]

Any reason not to just use the WriteFile method?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
J

Jerry Camel

When I tried it with Response.WriteFile, larger files just ended up with a "Page Not Found" error.

The code below seems to work - there's something strange going on. I tried it with three files:

File1: 66,854K
File2: 74,902K
File3: 158,262K

Files 1 and 3 work without a problem. File 2 hangs every time. This is really making me crazy! What's the problem with 74 Meg if you can handle 158 Meg just fine?

Anyone? Please!?!??!?!

Jerry
Any reason not to just use the WriteFile method?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
J

Jerry Camel

The dialog seems to pop up pretty quickly. Why? Is that another known issue?

How do I get ahold of the "very messy and complex way"?

Jerry
Jerry,

If you solve this, it will be amazing. I spend days last week researching ths issue and read about developer teams spending months trying to get a solution, and finally did (but in a very messy and complex way). I hope you get it though...we will all be happy!!!

Earl

BTW, with the current solution you have so for, does the dowload dialog pop up to the client right away?

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
J

Jerry Camel

And just to make things even more frustrating, File2 works from another workstation. I wonder if I've got some IE security patch on this box that doesn't like files with specific byte counts...


When I tried it with Response.WriteFile, larger files just ended up with a "Page Not Found" error.

The code below seems to work - there's something strange going on. I tried it with three files:

File1: 66,854K
File2: 74,902K
File3: 158,262K

Files 1 and 3 work without a problem. File 2 hangs every time. This is really making me crazy! What's the problem with 74 Meg if you can handle 158 Meg just fine?

Anyone? Please!?!??!?!

Jerry
Any reason not to just use the WriteFile method?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
E

Earl Teigrob

WriteFile blows up when using very large files (500m+). It tries to buffer the entire file to the server before sending, gives no notice to the user, takes forever and finally crashed the server. A slight problem...
Any reason not to just use the WriteFile method?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
E

Earl Teigrob

Read this

http://www.dotnetjunkies.com/Article/E9BE4431-3561-4A64-88C8-A49B2E50CBFA..dcik


The dialog seems to pop up pretty quickly. Why? Is that another known issue?

How do I get ahold of the "very messy and complex way"?

Jerry
Jerry,

If you solve this, it will be amazing. I spend days last week researching ths issue and read about developer teams spending months trying to get a solution, and finally did (but in a very messy and complex way). I hope you get it though...we will all be happy!!!

Earl

BTW, with the current solution you have so for, does the dowload dialog pop up to the client right away?

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
E

Earl Teigrob

When using Writefile, the entire file is cached to the server before the dialog box is displayed, which can take a long time on large files...(if the server does not crash, of course)
The dialog seems to pop up pretty quickly. Why? Is that another known issue?

How do I get ahold of the "very messy and complex way"?

Jerry
Jerry,

If you solve this, it will be amazing. I spend days last week researching ths issue and read about developer teams spending months trying to get a solution, and finally did (but in a very messy and complex way). I hope you get it though...we will all be happy!!!

Earl

BTW, with the current solution you have so for, does the dowload dialog pop up to the client right away?

I thought I had finally figured out how to control the downloads from my page. I was having issues with large files, but after much research I came up with the following code. The download seems to proceed without issue, but never terminiates. The byte count stops incrementing, but the dowload dialog never closes. (Until I hit cancel.) What's keeping the download from ending properly? I'm pretty close to finishing this app - any help is greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(), FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to download?


Thanks again!

- Jerry
 
M

Malek

did you try to use smaller chunks (I have used 2k chunks but I had low user
load and files not really getting over 70Mb)... maybe that could help. If
not, probably you should go with the dotnetjunkies method of using
ISAP+HttpHandler

WriteFile blows up when using very large files (500m+). It tries to buffer
the entire file to the server before sending, gives no notice to the user,
takes forever and finally crashed the server. A slight problem...
Any reason not to just use the WriteFile method?

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.

I thought I had finally figured out how to control the downloads from my
page. I was having issues with large files, but after much research I came
up with the following code. The download seems to proceed without issue,
but never terminiates. The byte count stops incrementing, but the dowload
dialog never closes. (Until I hit cancel.) What's keeping the download
from ending properly? I'm pretty close to finishing this app - any help is
greatly appreciated. Thanks.

Dim fStream As FileStream
Dim bytesToGo As Long
Dim bytesRead As Long
Dim byteBuffer(1048576) As Byte

fStream = New FileStream("C:\DepotRoot\" & e.CommandArgument(),
FileMode.Open, _
FileAccess.Read, FileShare.Read)
bytesToGo = fStream.Length
Response.BufferOutput = False
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=""" & _
dr("FileName") & """")
Response.Flush()
While (bytesToGo > 0)
If (Response.IsClientConnected) Then
bytesRead = fStream.Read(byteBuffer, 0, 1048576)
Response.OutputStream.Write(byteBuffer, 0, bytesRead)
Response.Flush()
bytesToGo -= bytesRead
Else
bytesToGo = -1
End If
End While

Response.Flush() 'This is kinda redundant, but it was worth a shot.
fStream.Close() 'Close the stream on the server side.
Response.End() 'Shouldn't this tell the browser to stop trying to
download?


Thanks again!

- Jerry
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top