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
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
  • 4,066
  • 10
  • 38
  • 54
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 =…
user2015534
  • 89
  • 1
  • 1
  • 6
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
  • 29
  • 2
  • 10
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
  • 3,379
  • 2
  • 26
  • 38
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
  • 591
  • 3
  • 13
  • 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,740
  • 10
  • 42
  • 76
0
votes
2 answers

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
  • 971
  • 1
  • 13
  • 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
  • 95
  • 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
5