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"
    };
}
59 questions
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
  • 2,849
  • 2
  • 31
  • 46
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
  • 307
  • 1
  • 3
  • 18
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
  • 2,815
  • 5
  • 38
  • 73
0
votes
2 answers

ASP.NET MVC FileContentResult SLOW

We are using it to return a file for an export. When we run this export on a lot of records, it takes close to 10 minutes to run. Here is a code snippet of the code that actually calls the File() method and returns the result. Public Function…
Scott
  • 3,534
  • 7
  • 34
  • 51
0
votes
1 answer

How to Display PDF stream in MVC

I am using MVC to display the PDF content in View, but it is not rendering properly. Controller Action: [HttpPost] public ActionResult GetDocumentContent() { byte[] result; result =…
0
votes
1 answer

TempData not retaining value in FileContentResult

I have the following code: [Authorize] [HttpGet] public FileContentResult DownloadMsgAsPdf(string FileId, string outer = "") { var Results = (SearchResult)TempData["Results"]; var msg = Results.emails[FileId]; ... …
user2463732
  • 109
  • 2
  • 9
0
votes
0 answers

Nothing happens when returning File in IE11

I have a method looking like this: public FileContentResult DownloadFile() { // Lots of code fileData = myWebService.GetFileBytes(); return File(fileData, "application/zip", "myZippedFile.zip"); } This method is working fine in Firefox,…
0
votes
1 answer

MVC Add image alt tag to FileContentResult

I am using a FileContentResult method to fetch a byte array from the database and render an image in the view. Works great but I can't figure out how to add an image alt tag (it would be the record name associated with the database record). I can…
GDB
  • 2,365
  • 2
  • 23
  • 31
0
votes
0 answers

ASP MVC4 Return File Memory spike in application pool

When I return for example a pdf from my controller, my application pool spikes up, if I download the file 10 times, my app pool crashes, is there any way to clear the memory after sending the file? I Used return File(ByteArrayOfFile,…
0
votes
2 answers

Display file (PDF/TXT) on form brought from Database in MVC ASP.NET

I want to display file on my form using MVC. I am bringing a Byte[] array data from the Database, and using FileContentResult I am converting it into a file.I want to now display this file on my page for viewing . How can it be acheived. What code…
Mangesh Kaslikar
  • 551
  • 3
  • 11
  • 23
0
votes
1 answer

Modify result from ajax request

Is it possible to retrieve some (in this case) text with an ajax request and modify it before showing it in e.g. a div? I've got the following code $.ajax({url: "Files/" + par + ".php", success: function(result){ $("#box").html(result); } Where…
Gooey
  • 4,430
  • 10
  • 39
  • 72
0
votes
1 answer

FileContentResult render in View without specific Controller Action

I have same action in a controller that fetch from db for example a Employee with a name, age, image (byte[]). So I store the info in ViewBag. Then in the View the specific code for the image is: Logo But when I…
gonzalomelov
  • 931
  • 1
  • 11
  • 30
0
votes
0 answers

Rendering image in a View

I'm trying to show some picture for user in a strongly typed View.. In Model members there is one that represents contents of image (ex. jpeg) How should I pass this content to img tag to render this image? model looks like: publiс class Image…
versus
  • 85
  • 6
-1
votes
1 answer

Reading all lines from a HttpRequestedFileBase

i'm fetching a file by HttpRequestedFileBase, txt type, and I need to read each line in the file and store those line in variables to workin with them. But I'm wondering if i should convert the file to read it. Also I get some errors whiles I was…
1 2 3
4