Click here to Skip to main content
14,736,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted
Updated 13-Mar-20 4:20am
v2

1 solution

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900