-2

I was trying to create excelpackage download function. When i try it on my server or on my local development server, the download button works and it sends Excel file to the browser. But after i deployed and try to download from client, it returns nothing.

Result using Chrome

Result using Chrome

Result using Firefox

enter image description here

Here is my code :

if (Response.IsClientConnected)
    {
        Response.Clear();
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.AddHeader("content-disposition", "attachment;  filename=" + departmentName + ".xlsx");
        Response.BinaryWrite(excelPackage.GetAsByteArray());
        Response.Flush();
        Response.Close();
    }

I tried to follow the instructions that were provided here,

Microsoft Office Excel cannot access the file 'c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx'

But still won't fix my problem.

Community
  • 1
  • 1
donthurtme
  • 1,347
  • 1
  • 10
  • 16

1 Answers1

0
if (Response.IsClientConnected)
{
    Response.Clear();
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    Response.AddHeader("content-disposition", "attachment;  filename=" + departmentName + ".xlsx");
    Response.BinaryWrite(excelPackage.GetAsByteArray());
    Response.Flush();
    Response.End();
}

Somehow when i change

Response.Close()

to

Response.End()

It works.

donthurtme
  • 1,347
  • 1
  • 10
  • 16