How to return an Excel file from ASP.NET Core Web API web-app?
<p>In similar questions, with this code works to download a PDF:</p>

<blockquote>
  <p>I'm testing with local files (.xlsx, .pdf, .zip) inside the Controller folder.</p>
</blockquote>

<p><a href="https://stackoverflow.com/questions/34853072/how-to-return-file-from-asp-net-5-web-api">Similar Question Here</a></p>

<pre><code>[HttpGet("downloadPDF")]
public FileResult TestDownloadPCF()
{
   HttpContext.Response.ContentType = "application/pdf";
   FileContentResult result = new FileContentResult
   (System.IO.File.ReadAllBytes("Controllers/test.pdf"), "application/pdf")
    {
      FileDownloadName = "test.pdf"
    };
   return result;
}
</code></pre>

<p><a href="https://i.stack.imgur.com/Us3al.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Us3al.png" alt="This works great!"></a></p>

<p>But when another file?, for example an Excel File(.xlsx) or ZIP File(.zip), testing does not work properly.</p>

<p>Code : </p>

<pre><code>[HttpGet("downloadOtherFile")]
public FileResult TestDownloadOtherFile()
{
  HttpContext.Response.ContentType = 
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
  FileContentResult result = new FileContentResult(System.IO.File.ReadAllBytes("Controllers/test.xlsx"), 
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
  {
    FileDownloadName = "otherfile"
   };
  return result;
}
</code></pre>

<p>Result:
<a href="https://i.stack.imgur.com/aKSCK.png" rel="noreferrer"><img src="https://i.stack.imgur.com/aKSCK.png" alt="enter image description here"></a></p>

<p>I also did tests with the following Content-Type:</p>

<ul>
<li>"Application / vnd.ms-excel"</li>
<li>"Application / vnd.ms-excel.12"</li>
</ul>

<p>Getting the same result.</p>

<p><strong>Which is the right way to return any file type?</strong></p>

<p>Thanks for your answers</p>