FileContentResult for System.AspnetCore vs System.Web.Mvc


To be fair, both System.Web.Mvc and Microsoft.AspNetCore.Mvc supports FileContentResult when returning file. The only difference is Microsoft.AspNetCore.Mvc comes with a helper method called File that make this faster.


Microsoft.AspNetCore.Mvc way


[HttpGet("{id}"]
 public async Task Download(string id)

       return File(stream, "application/octet-stream"); // returns a FileStreamResult
}


System.Web.Mvc (5.2.3) way

public System.Web.Mvc.ActionResult ExportCSV()
{
            byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\tmp\csvfile.csv");         
            return new System.Web.Mvc.FileContentResult(fileBytes, "text/csv");           
}



Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm