Hi,
I am trying to save the excel workbook as an array of bytes and displaying it in the web browser as follows
Dim ms As New IO.MemoryStream
xls.Save(ms, FileFormatType.Excel2000)
Dim Bytes As Byte() = ms.GetBuffer()
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.Cache.SetExpires(Now.AddDays(-1))
Response.AddHeader("pragma", "no-cache")
Response.Buffer = True
Response.ContentType = "application/ms-excel"
Response.AppendHeader("content-disposition", "attachment; filename=Excelfile.xls")
Response.OutputStream.Write(Bytes, 0, Bytes.Length - 1)
The above code works most of the times, but sometimes it gives an error when opening the excel file. Pls see the attached file.
When the above code is changed as follows, it works fine.
Response.OutputStream.Write(Bytes, 0, Bytes.Length)
Can you pls tell us what the problem is, as to why the error is inconsistent?
Thanks,
Pradeepa.