Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get byte[] from FileResult?

Is it possible to get byte[] from FileResult in C#?

like image 317
Friend Avatar asked Nov 13 '14 17:11

Friend


People also ask

What is FileContentResult?

FileContentResult is an ActionResult that when executed will write a binary file to the response. public FileContentResult DownloadContent() { var myfile = System.IO.File.ReadAllBytes("wwwroot/Files/FileContentResult.pdf"); return new FileContentResult(myfile, "application/pdf");


1 Answers

FileResult is an abstract class so that won't be the underlying instance type - assuming the correct overload is used then you should be able to cast it to a FileContentResult

if (result is FileContentResult data)
{
    var content = data.FileContents;
}
like image 189
James Avatar answered Nov 10 '22 22:11

James