Error on save to excel

Jul 3, 2012 at 8:18 AM
Edited Jul 3, 2012 at 8:24 AM

I have the samples of the EPPlus working ok but when I try to add save to excel option in my code I keep getting the error below:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.
I have an UpdatePanel which displays a dynamically created table which is created on a button click event. Then I have another button, Save To Excel which creates the excel file and asks the user where to save it (it actually works fine if added to an empty project for example) This is how I end my SaveToExcel method:
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;  filename=excelFile.xlsx");
package.SaveAs(Response.OutputStream);
Response.End();
I have been stepping through the whle SaveToExcel() method and it errors on
Response.End();

 

How to fix that?

Jul 4, 2012 at 11:05 AM

try to replace your 2 last lines of code with this:

bytes = package.GetAsByteArray();

Response.BinaryWrite(bytes);

Response.End();