0
votes

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.

1
Why do you have square brackets around Response.End? Typo? If not that is probably the reason - remove them and retry - Kevin Main
i did try that and its the same problem too. - developer
In that case see this question stackoverflow.com/questions/10756359/… - Kevin Main

1 Answers

2
votes

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