A
Ali
I need a functionality where my clients download Excel files and after they
do, I do some processing. Downloading is easily achieved using a anchor or
hyperlink tag, but that does not give me the full functionality I am after.
So, I came up with a way to download the files using a stream but after I
download the file and try to open it in Excel I get garbage.
This is the code I use for the download function. Please help if you have
any ideas or suggestions. Thanks in advance.
Ali
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim path As String
Dim fs As New FileStream(path, FileMode.Open)
Dim byteRead As Integer
path = Server.MapPath(Request("fileToDownload"))
Response.ClearHeaders()
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" &
Request("fileToDownload").ToString
Response.ContentType = "application/XYZ"
byteRead = fs.ReadByte()
While byteRead <> -1
Response.Write(byteRead)
byteRead = fs.ReadByte()
End While
fs.Close()
End Sub
do, I do some processing. Downloading is easily achieved using a anchor or
hyperlink tag, but that does not give me the full functionality I am after.
So, I came up with a way to download the files using a stream but after I
download the file and try to open it in Excel I get garbage.
This is the code I use for the download function. Please help if you have
any ideas or suggestions. Thanks in advance.
Ali
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim path As String
Dim fs As New FileStream(path, FileMode.Open)
Dim byteRead As Integer
path = Server.MapPath(Request("fileToDownload"))
Response.ClearHeaders()
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" &
Request("fileToDownload").ToString
Response.ContentType = "application/XYZ"
byteRead = fs.ReadByte()
While byteRead <> -1
Response.Write(byteRead)
byteRead = fs.ReadByte()
End While
fs.Close()
End Sub