title: Download Excel File in .net core web api
body: <p>I'm trying to create &amp; download the excel file in asp .net core web api. Whenever I hit the service from postman or Advanced Rest Client, Instead of downloading the file I'm getting the JSON data of the file content as response. My code is like below :</p>
  
  <pre><code>        [HttpGet]
          [Route("GetLogsPdfORExcel")]
          public IActionResult GetLogsPdfORExcel()
          {
  
  
              var result = _dataContext.GetLogsPdfORExcel();
              if (result != null)
              {
                  this.ExportExcel(result);
              }
  
              return Ok(result);
          }
  
          public FileStreamResult ExportExcel(DataTable dt)
          {
              string excelName = "LogsRecord";
  
              ExcelPackage package = new ExcelPackage();
              ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("sheet1");
              int currentRowNo = 5;
              int totalRows = dt.Rows.Count;
              int k = 0;
              foreach (DataColumn column in dt.Columns)
              {
                  worksheet.Cells[currentRowNo, k + 1].Value = column.ColumnName;
                  k++;
              }
              currentRowNo++;
              for (int i = 0; i &lt; dt.Rows.Count; i++)
              {
                  for (int j = 0; j &lt; dt.Columns.Count; j++)
                  {
                      worksheet.Cells[currentRowNo, j + 1].Value = Convert.ToString(dt.Rows[i][j]);
                  }
                  currentRowNo++;
              }
  
              int columnCount = dt.Columns.Count;
              for (int i = 1; i &lt;= columnCount; i++)
                  worksheet.Column(i).AutoFit();
              worksheet.Row(1).Height = 55;
              worksheet.SelectedRange["A1"].Style.Font.Size = 14;
              worksheet.Row(5).Style.Font.Bold = true;
  
  
  
              using (var memoryStream = new MemoryStream())
              {
                  memoryStream.Position = 0;
                  var contentType = "application/octet-stream";
                  var fileName = "fileName.xlsx";
                  return File(memoryStream, contentType, fileName);
              }
          }
  
  </code></pre>
  
  <p>Here whenever I hit my service, I need directly my file needs to get download.</p>