saravana__ Ответов: 1

проблема загрузки файлов в браузере chrome


Я использую этот код для загрузки файлов...firefox и IE также, что кодирование работает нормально, но в google chrome не работает, что код скачать полную страницу aspx..

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()


пожалуйста, помогите мне..

1 Ответов

Рейтинг:
7

saravana__

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()