0
 public ActionResult ExportLeadTimingReport(JLRReportSearchCriteriaViewModel searchCriteria)
    {
        OperationResponse<DataTable> LeadTimingReport = new OperationResponse<DataTable>();
        LeadTimingReport.Value = new DataTable();
          byte[] file = LeadManager.GetJLRLeadTimingReportForExport(searchCriteria);

                HttpContext.Response.ClearContent();
                HttpContext.Response.Clear();
                HttpContext.Response.Buffer = true;
                HttpContext.Response.AddHeader("content-disposition", "attachment; filename=Export.xlsx");
                HttpContext.Response.ContentType = "application/force-download";
                HttpContext.Response.Charset = "";

                HttpContext.Response.BinaryWrite(file);
                HttpContext.Response.End();

                return null;
    }

Returns empty excel file. But binary array contains data, but when its called it gives blank excel file.

Wintergreen
  • 236
  • 1
  • 9

1 Answers1

1

Can you please modify the code as given below

public ActionResult ExportLeadTimingReport(JLRReportSearchCriteriaViewModel searchCriteria)
    {
       OperationResponse<DataTable> LeadTimingReport = new OperationResponse<DataTable>();
       LeadTimingReport.Value = new DataTable();
       byte[] file = LeadManager.GetJLRLeadTimingReportForExport(searchCriteria);

       this.Response.ContentType = "application/vnd.ms-excel";
       return File(file , "application/vnd.ms-excel");
}
Amal Dev
  • 1,938
  • 1
  • 14
  • 26
  • but it shows this error "Server cannot set status after HTTP headers have been sent." – Wintergreen May 18 '15 at 07:02
  • Can you try any of the solution mentioned here. http://stackoverflow.com/questions/2383169/server-cannot-set-status-after-http-headers-have-been-sent-iis7-5 – Amal Dev May 18 '15 at 07:08