ActionResult returning a Stream

Updated for MVC5 2020:

my previous answer was dated.

as of now, the File returns different type of ActionResult depends on given arguments

// to return FileStreamResult
return File(memoryStream, "application/pdf");
// or..
return File(memoryStream, "application/pdf", "file_name");

Use FileStreamResult:

MemoryStream stream = someService.GetStream();

return new FileStreamResult(stream, "application/pdf")

Leave a Comment