Chrome浏览器中的下载文件问题 [英] download files problem in chrome browser
本文介绍了Chrome浏览器中的下载文件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码下载文件... firefox和IE,该编码也可以正常工作,但在谷歌浏览器中该代码无法下载完整的aspx页面..
I am using this code to download files...firefox and IE also that coding is works fine but in google chrome is not working that code download full aspx page..
Dim strEncFileName As String
strEncFileName = CType(e.CommandSource, LinkButton).CommandArgument
Dim objRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.sitename.com/foldername/" + strEncFileName), HttpWebRequest)
Dim objResponse As HttpWebResponse = DirectCast(objRequest.GetResponse(), HttpWebResponse)
Dim bufferSize As Integer = 1
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.AppendHeader("Content-Disposition:", "attachment; filename=" + strEncFileName + "")
Response.AppendHeader("Content-Length", objResponse.ContentLength.ToString())
Response.ContentType = "application/download"
Dim byteBuffer As Byte() = New Byte(bufferSize) {}
Dim memStrm As New MemoryStream(byteBuffer, True)
Dim strm As Stream = objRequest.GetResponse().GetResponseStream()
Dim bytes As Byte() = New Byte(bufferSize) {}
While strm.Read(byteBuffer, 0, byteBuffer.Length) > 0
Response.BinaryWrite(memStrm.ToArray())
Response.Flush()
End While
Response.Close()
Response.[End]()
memStrm.Close()
memStrm.Dispose()
strm.Dispose()
请帮助我..
plz help me..
推荐答案
Dim strEncFileName As String
strEncFileName = CType(e.CommandSource, LinkButton).CommandArgument
Dim objRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.sitename.com/foldername/" + strEncFileName), HttpWebRequest)
Dim objResponse As HttpWebResponse = DirectCast(objRequest.GetResponse(), HttpWebResponse)
Dim bufferSize As Integer = 1
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.AddHeader("Content-Disposition", "attachment; filename="+strEncFileName+"; size=" + objResponse.ContentLength.ToString())
Response.ContentType = "application/download"
Dim byteBuffer As Byte() = New Byte(bufferSize) {}
Dim memStrm As New MemoryStream(byteBuffer, True)
Dim strm As Stream = objRequest.GetResponse().GetResponseStream()
Dim bytes As Byte() = New Byte(bufferSize) {}
While strm.Read(byteBuffer, 0, byteBuffer.Length) > 0
Response.BinaryWrite(memStrm.ToArray())
End While
Response.Flush()
Response.Close()
Response.[End]()
memStrm.Close()
memStrm.Dispose()
strm.Dispose()
这篇关于Chrome浏览器中的下载文件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文