I am having some difficulty saving a workbook to the Response stream.
I can load the .xlsx from disk and do my updates, then I can wb.SaveToFile("foo.xlsx"), which works fine and reflects the changes that I made.
Tried to write the file to the Response stream, wb.SaveToStream(Response.OutputStream), but no luck.
Tried to simply read in the saved file from disk and stream it to Response but cannot seem to get that to work either.
Might have to do with the encoding. not sure.
- Code: Select all
Using sr As System.IO.StreamReader = New System.IO.StreamReader("foo.xlsx")
content = sr.ReadToEnd()
End Using
Then I write the file to the Response stream.
- Code: Select all
Response.BinaryWrite(System.Text.Encoding.ASCII.GetBytes(content))
File is saved yet cannot open the .xlsx file.
Error says "The file format and extension don't match. file could be corrupted or unsafe."
I feel that I am close but just cannot seem to get over the hump on this one.
Thanks,
Bill