Questions tagged [filecontentresult]

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"
    };
}
71 questions
2
votes
1 answer

ASP.NET MVC FileContentResult inline PDF filename not showing in browser title

.NET Framework 4.7.2 MVC project I have a controller action that dynamically loads a PDF to return inline to the browser. Everything is working, except the filename is not showing in the browser title bar or the tab. Instead, the browser is showing…
Bryan Williams
  • 452
  • 1
  • 5
  • 17
2
votes
0 answers

Render FileContentResult using javascript

I have an Web API written in Core 2 that returns a FileContentResult. You need to do a GET with an Auth Token in the header for it to work. If you try it with postman, the file renders fine and it also renders well in an MVC View. Now we have an…
Nick
  • 2,877
  • 2
  • 33
  • 62
2
votes
1 answer

C# FileContentResult File Download In Custom Folder

I'm using FileContentResult method to download a generated PDF file. After running this code public FileContentResult genPDF(PDFFileData m) { try { var FL = generatePDF(m); var FLBytes =…
user6791278
2
votes
1 answer

How do I convert a FileContentResult to a FileStreamResult?

I have a FileContentResult obtained from a byte array and want to turn it into a FileStreamResult. Is this possible? If so, how?
SantLev
  • 140
  • 3
  • 15
2
votes
1 answer

Chrome modifying long file names when download them (using c# FileContentResult)

In a list of generated reports, have a link to download them. The contents of these reports are stored in the database. When I perform the download a report, use the code below: return new FileContentResult (report.FileContents, mimeType) { …
Anzolin
  • 43
  • 7
1
vote
0 answers

Send document to client server from .net server

I have an API that offers a file translation service. I have been able to generate a new the new translated file but I have not been able to get it to the client correctly, because the document downloaded it is not readable. This is my controller…
1
vote
0 answers

How to handle null or empty value in FileContentResult return type in c#

I have a method to download files with return type FileContentResult am getting byte array from API and downloading file from that but not getting how to handle if i get null value from api. public FileContentResult DownloadEID() { byte[]…
Surya
  • 265
  • 1
  • 3
  • 10
1
vote
0 answers

How to consume API call that returns FileContentResult programmatically

I'm trying to consume an API that my team created that returns a FileContentResult (a PDF File) for mobile. I have written some code to retrieve the byte array of that result as shown below. Line that returns PDF file in the API return new…
Anthony R
  • 89
  • 1
  • 10
1
vote
2 answers

Creating a .NET Standard library that uses other MVC libraries

I am trying to create a .NET Standard 2.0 library that is to be used by multiple MVC applications which may be .NET Framework or .NET Core. This particular library is supposed to export data as an excel file. To do this I need to use…
1
vote
0 answers

Application experienced internal error loading the SSL libraries in asp.net MVC and FileContentResult

The MVC application am developing has feature to upload/download files that supports files of type- xls,xlsm,xlsx, doc,docx,pdf,msg etc. Recently, the code for downloading the file got modified to return FileResult form action method instead of,…
1
vote
1 answer

Url.Action download action causes new tab to open/close quickly before download

I have some code that calls a controller in razor view like  @item.Title The controller action returns a…
lloyd
  • 1,089
  • 1
  • 17
  • 39
1
vote
1 answer

Trouble exporting to excel from mvc action

I created a simple action to download some content as excel file: public FileResult ExportToExcel() { string filename = "list.xlsx"; string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; …
nickornotto
  • 1,946
  • 4
  • 36
  • 68
1
vote
2 answers

C# - Byte arrays and file extensions

I have a byte array that I've downloaded which lacks a file extension. I need to give this file an extension, which in my case will always be .gif, and convert back to a byte array. I'm accomplishing the first step thus: FileContentResult file =…
lobsterhat
  • 157
  • 2
  • 4
  • 15
1
vote
1 answer

MVC Controller FileContentResult method not being called

My test setup is comprised of a view with a foreach that iterates over a simple model with the objective of rendering an image for each item in the model collection. Inside the loop are two @Url.Action helpers that call FileContentResult methods in…
GDB
  • 3,379
  • 2
  • 26
  • 38
1
vote
1 answer

MVC Database Image and Default Image

have the following image, from a database... And the controller.... public FileContentResult GetLogo(int ID) { var GetImage = (from x in repository.GetClientLogo …
Sherry8212
  • 67
  • 1
  • 11