I\'m working on a web service using ASP.NET MVC\'s new WebAPI that will serve up binary files, mostly .cab
and .exe
files.
The following co
You can make use of the IActionResult interface in an API controller method, like so...
[HttpGet("GetReportData/{year}")]
public async Task GetReportData(int year)
{
// Render Excel document in memory and return as Byte[]
Byte[] file = await this._reportDao.RenderReportAsExcel(year);
return File(file, "application/vnd.openxmlformats", "fileName.xlsx");
}
This example is simplified, but should get the point across. In .NET Core this process is so much simpler than in previous versions of .NET - i.e. no setting response type, content, headers, etc.
Also, of course the MIME type for the file and the extension will depend on individual needs.
Reference: SO Post Answer by @NKosi