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
0
votes
1 answer

Opening a byte stream file using asp.net mvc

Im my asp.net mvc application I have a enclosing the thumb image of the file in an aspx page loaded in an iframe. I want to open the file with an Open/Save dialogbox. The file is uploaded to the database in image datatype. My aspx page has the…
sujanr
  • 13
  • 5
0
votes
1 answer

.net core web api File randomly loads only part of the response

I am loading an image from S3 bucket as byte[] and send it as a response from my asp.net core 3.1 web API controller method. Here is my code: public async Task GetImage(string documentId, int pageId) { var imageArray =…
Bashir Magomedov
  • 2,841
  • 4
  • 28
  • 44
0
votes
2 answers

Read file and its properties from API and download it in Angular Client

Need to download dynamic files which is returned from the api in the client side based on its type. This is what i have My api controller it looks like this public async Task GetFile(int id) { …
Nithin Paul
  • 2,169
  • 3
  • 33
  • 55
0
votes
1 answer

Angular 7 pdf display file from blob

I'm returning a FileContentResult from my c# .NET API, in my angular 7 application I receive it as a blob with HttpClient and then use the following to open a new tab and try to display it. this.myService.GetPdfBlob().subscribe(data => { var…
Kevin
  • 827
  • 1
  • 7
  • 18
0
votes
1 answer

Which style is the better and efficiency way to export csv file

I have two solutions to export CSV file with .net MVC, which use the NuGet package named CsvHelper. Those two solutions work the same result, but I curious which is the better one can efficient with CPU, Memory, disk io? there's a helper with…
kkman021
  • 163
  • 1
  • 11
0
votes
1 answer

FileContentResult not generating file when called from AJAX post

I apologize if this is a little vague, however the issue presenting itself isnt giving too much away. I have been writting an application that uses MigraDoc to generate PDFs. The controller method used to generate and download the PDF is as…
CJH
  • 1,266
  • 2
  • 27
  • 61
0
votes
1 answer

How to download the file sent in JSON FileContentResult from a web api

I am a getting a FileContentResult from a web API for my desktop application. { "fileContents": "JVBERi0xLjMNCjEgMCBvYmoNNzQ3Ng0KJSVFT0Y=", "contentType": "application/octet-stream", "fileDownloadName": "", "lastModified": null, …
kanmani24
  • 31
  • 5
0
votes
1 answer

VS UnitTesting a FileContentResult - Can I generate the file when testing

I want to Unit Test a method that returns a FileContentResult of a PDF file. I am doing some tests to check the content type & file name, but it would be great if I could also generate the PDF somehow as part of the test? I currently have a method…
CJH
  • 1,266
  • 2
  • 27
  • 61
0
votes
3 answers

java.lang.ArrayIndexOutOfBoundsException: 4

I am working on extracting values from a tab separated text file into a list in groovy. But am running into the ArrayIndexOutOfBoundsException. Code println("Reading File Contents") def fullArray = new String[31721][4] def availableArray = new…
0
votes
1 answer

Strange conversion of bytes to and from string

I have a mini server byte[] content = fileManager.get(request.getUri()); Here I get the contents of the files on the server Next I produce compression and chunking content = process(content, response); private byte[] process(byte[] content,…
0
votes
1 answer

MigraDoc Images - When can I delete the images

I am using MigraDoc for PDF Exports and part of the application allows the user to Embed an image (MigraDoc.DocumentObjectModel.Shapes.Image) into a Document. The images exist in the database and I am not able to upgrade to the latest MigraDoc BETA…
CJH
  • 1,266
  • 2
  • 27
  • 61
0
votes
2 answers

ASPNET MVC: I get "The view X or its master was not found or no view engine..." Error on Method that return JSON ContentResult

I have a method that return json ContentResult. I call on from JavaScript file like this: $scope.GetUserRoles = function () { $http({ method: "GET", url: Current.VirtualUrl + "Store/Counting/GetUserRoles" …
0
votes
1 answer

Why loading image inside an Iframe from parent as FileContentResult failed?

I have a file upload inside an Iframe. when a user upload an image this file upload send the image to the server and server pass the file name to the file upload. Now I use this name and send it to an action that gives me image file as…
n.y
  • 3,343
  • 3
  • 35
  • 54
0
votes
1 answer

MVC FileContentResult for Image returns binary to screen

This is a head scratcher. I have code that works great in one project. I am reusing it in another and it doesn't work. Not sure what I missed. I am trying to return an image from my MVC controller to an image control. Method is: public ActionResult…
Cef
  • 661
  • 1
  • 6
  • 26
0
votes
1 answer

How to send byte array as paramater to HTML.Action?

I have been working with charts today And I think that i finaly found a way for it all to work but I encountered an issue that I don't know how to pass. Create my Charts in my controller: foreach (var m in model[0].HistoryValues) { …
ThunD3eR
  • 3,216
  • 5
  • 50
  • 94