0

I am having some difficulties exporting excel file using NPOI dll through ASP.NET page.

Basically, I am able to populate the cells with no exception, however right at the few last steps where I need to export out the excel, it throws an exception when it tries to run Response.End.

Dim ms As New MemoryStream
xlWorkbook.Write(ms)
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=M4_Control_Chart.xls")
Response.Clear()
Response.BinaryWrite(ms.GetBuffer())
Response.End()

I dont get a lot of information from the exception, it just says "Unable to evaluate expression"

Does anyone have any idea how to fix this?

Thanks.

developer
  • 718
  • 9
  • 28

1 Answers1

2

Flush your stream before you read the buffer: ms.Flush()

David Robbins
  • 9,996
  • 7
  • 51
  • 82