FileContentResult is an ActionResult in ASP.NET MVC that is used to send byte array as HTTP response.
FileContentResult is an ActionResult in ASP.NET MVC that is used to send byte array as HTTP response. This class is derived from FileResult base class. This ActionResult is useful in several scenarios such as:
- The content of a file is served from a database,
- The binary content is generated dynamically in memory e.g. dynamically generated image, PDF files etc.
To show 'Save As' dialog box by the browser, set FileDownloadName property value. If you set this value, the appropriate HTTP header will be added in response header:
Content-Disposition: attachment; filename=<FileDownloadName>
An example use could be:
public ActionResult GeneratePdf()
{
byte[] byteContents = GetFileFromDatabase();
return new FileContentResult(byteContents, contentType: "application/pdf")
{
FileDownloadName = "FileName.pdf"
};
}