0

I am iterating through multiple recordsets to create multiple Excel worksheets that can take up to 30 seconds for the results, so I want to provide the user with feedback. A Processing.gif would be fine, but I would rather list the name of each Excel tab as it is being worked on.

Either way, no status shows up, just a blank page while the Excel file is being built.

Here is very sparse default.aspx

<form id="form1" runat="server">
    <div>
        <!-- never shows -->
        <asp:Image AlternateText="Processing for download" ImageUrl="/Images/Wait_Loader.gif"
    </div>
</form>

The code uses NPOI to build the spreadsheet file.

//*** New worksheet
Sheet sheet;
sheet = workbook.CreateSheet(sWorksheetName);


// Save the Excel spreadsheet to a MemoryStream and return it to the client
using (var exportData = new MemoryStream())
{
    workbook.Write(exportData);

    string saveAsFileName = sFileName + ".xls";

    Response.ContentType = "application/vnd.ms-excel";
    Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
    Response.Clear();
    Response.BinaryWrite(exportData.GetBuffer());
    Response.End();
}

All of this code works just fine, but when try to set the text of a label control or view a processing.gif, it is still just a blank screen. When I tried a Response.Write, I got statuses followed by the error Server cannot set status after HTTP headers have been sent

It seems like there is a collision between my Response.Writes and the NPOI using the Response object to write to the file.

How do I get something besides a blank window?

Andy In NC
  • 112
  • 1
  • 8
  • It'd be best to do something outside the normal request/response to update the status. AJAX polling or SignalR push notifications etc. Also, your Excel code should not be directly in your code behind. Follow proper separation of concerns. – mason Oct 12 '16 at 20:20
  • I've never used SignalR push but I found this sample that seems useful. http://www.codeproject.com/Tips/672433/Real-time-notifications-with-SignalR I'll see about implementing next week. – Andy In NC Oct 14 '16 at 13:44

0 Answers0