为什么我的下载不会结束? [英] Why won't my download ever end?

查看:96
本文介绍了为什么我的下载不会结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我终于想出了如何从我的页面控制下载。我遇到了大文件的问题,但经过大量研究后,我想出了以下代码。下载似乎没有问题,但永远不会终止。字节计数停止递增,但下载对话框永远不会关闭。 (直到我点击取消。)什么是保持下载正确结束?我非常接近完成这个应用程序 - 非常感谢任何帮助。谢谢。


Dim fStream As FileStream

Dim bytesToGo As Long

Dim bytesRead As Long

Dim byteBuffer(1048576)As Byte


fStream =新FileStream(" C:\DepotRoot \"& e.CommandArgument(),FileMode.Open,_

FileAccess.Read,FileShare.Read)

bytesToGo = fStream.Length

Response.BufferOutput = False

响应。清除()

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 )然后

bytesRead = fStream.Read(byteBuffer,0,1048576)

Response.OutputStream.Write(byteBuffer,0,bytesRead)

Response.Flush()

bytesToGo - = bytesRead

Else

bytesToGo = -1

结束如果

结束时


Response.Flush()''这有点多余,但值得一试。

fStream.Close()''关闭服务器端的流。

Response.End()''这不应该告诉浏览器停止尝试下载吗?

再次感谢!


- Jerry

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

推荐答案

这是我的理论。

将ContentLength添加到标题中。


Response.AppendHeader(" ContentLength",Filesize.tostirng())

让我知道它是否有效。

乔治。


Jerry Camel < RL ***** @ msn.com>在消息新闻中写道:uo **************** @ tk2msftngp13.phx.gbl ...

我以为我终于想出如何控制从我的页面下载。我遇到了大文件的问题,但经过大量研究后,我想出了以下代码。下载似乎没有问题,但永远不会终止。字节计数停止递增,但下载对话框永远不会关闭。 (直到我点击取消。)什么是保持下载正确结束?我非常接近完成这个应用程序 - 非常感谢任何帮助。谢谢。


Dim fStream As FileStream

Dim bytesToGo As Long

Dim bytesRead As Long

Dim byteBuffer(1048576)As Byte


fStream =新FileStream(" C:\DepotRoot \"& e.CommandArgument(),FileMode.Open,_

FileAccess.Read,FileShare.Read)

bytesToGo = fStream.Length

Response.BufferOutput = False

响应。清除()

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 )然后

bytesRead = fStream.Read(byteBuffer,0,1048576)

Response.OutputStream.Write(byteBuffer,0,bytesRead)

Response.Flush()

bytesToGo - = bytesRead

Else

bytesToGo = -1

结束如果

结束时


Response.Flush()''这有点多余,但值得一试。

fStream.Close()''关闭服务器端的流。

Response.End()''这不应该告诉浏览器停止尝试下载吗?

再次感谢!


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

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

"Jerry Camel" <rl*****@msn.com> wrote in message news:uo****************@tk2msftngp13.phx.gbl...
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


我很欣赏回应,但那并不是做到这一点。我希望它至少能解决我发布的关于下载进度的另一个项目,但它也没有这样做。还有其他想法吗?


Jerry

" George Ter-Saakov" <无**** @ hotmail.com>在留言新闻中写道:Oy **************** @ TK2MSFTNGP11.phx.gbl ...

这是我的理论。

将ContentLength添加到标题中。


Response.AppendHeader(" ContentLength",Filesize.tostirng())

如果有,请告诉我工作。

乔治。


Jerry Camel < RL ***** @ msn.com>在消息新闻中写道:uo **************** @ tk2msftngp13.phx.gbl ...

我以为我终于想出如何控制从我的页面下载。我遇到了大文件的问题,但经过大量研究后,我想出了以下代码。下载似乎没有问题,但永远不会终止。字节计数停止递增,但下载对话框永远不会关闭。 (直到我点击取消。)什么是保持下载正确结束?我非常接近完成这个应用程序 - 非常感谢任何帮助。谢谢。


Dim fStream As FileStream

Dim bytesToGo As Long

Dim bytesRead As Long

Dim byteBuffer(1048576)As Byte


fStream =新FileStream(" C:\DepotRoot \"& e.CommandArgument(),FileMode.Open,_

FileAccess.Read,FileShare.Read)

bytesToGo = fStream.Length

Response.BufferOutput = False

响应。清除()

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 )然后

bytesRead = fStream.Read(byteBuffer,0,1048576)

Response.OutputStream.Write(byteBuffer,0,bytesRead)

Response.Flush()

bytesToGo - = bytesRead

Else

bytesToGo = -1

结束如果

结束时


Response.Flush()''这有点多余,但值得一试。

fStream.Close()''关闭服务器端的流。

Response.End()''这不应该告诉浏览器停止尝试下载吗?

再次感谢!


- Jerry
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
"George Ter-Saakov" <no****@hotmail.com> wrote in message news:Oy****************@TK2MSFTNGP11.phx.gbl...
Here is the my theory.
Add ContentLength: to the header.

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

"Jerry Camel" <rl*****@msn.com> wrote in message news:uo****************@tk2msftngp13.phx.gbl...
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


仅供参考 - 这似乎只是一个大问题下载。较小的下载工作正常。

Jerry Camel < RL ***** @ msn.com>在消息新闻中写道:uo **************** @ tk2msftngp13.phx.gbl ...

我以为我终于想出如何控制从我的页面下载。我遇到了大文件的问题,但经过大量研究后,我想出了以下代码。下载似乎没有问题,但永远不会终止。字节计数停止递增,但下载对话框永远不会关闭。 (直到我点击取消。)什么是保持下载正确结束?我非常接近完成这个应用程序 - 非常感谢任何帮助。谢谢。


Dim fStream As FileStream

Dim bytesToGo As Long

Dim bytesRead As Long

Dim byteBuffer(1048576)As Byte


fStream =新FileStream(" C:\DepotRoot \"& e.CommandArgument(),FileMode.Open,_

FileAccess.Read,FileShare.Read)

bytesToGo = fStream.Length

Response.BufferOutput = False

响应。清除()

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 )然后

bytesRead = fStream.Read(byteBuffer,0,1048576)

Response.OutputStream.Write(byteBuffer,0,bytesRead)

Response.Flush()

bytesToGo - = bytesRead

Else

bytesToGo = -1

结束如果

结束时


Response.Flush()''这有点多余,但值得一试。

fStream.Close()''关闭服务器端的流。

Response.End()''这不应该告诉浏览器停止尝试下载吗?

再次感谢!


- 杰瑞
FYI - This only seems to be a problem with larger downloads. The smaller downloads work just fine.
"Jerry Camel" <rl*****@msn.com> wrote in message news:uo****************@tk2msftngp13.phx.gbl...
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


这篇关于为什么我的下载不会结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆