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
1
vote
1 answer

KineticJS - asp.net MVC - Json save canvas data as a downladable PNG file

My project is asp.net MVC 3, I export the canvas data using the following script: $("#savePNG").click(function () { stage.toDataURL({ callback: function (dataUrl) { dataUrl =…
hncl
  • 2,295
  • 7
  • 63
  • 129
1
vote
1 answer

Load an image returned as a FileContentResult in Aviary Editor

I am currently working in an MVC project and my current requirement is to load an image in Aviary picture editor. The problem occurred to me is that, the image I selected using input type "file" is rendered to the view using FileContentResult, and I…
Anu
  • 127
  • 3
  • 12
1
vote
4 answers

Downloading excel file in asp.net mvc

What I'm trying to implement is giving the users the ability to export the grid data to an excel file and download it, with the help of a file save dialog. Here's how I have coded it right now - In Javascript - $.post("/irn/Identifier/Download", {…
neuDev33
  • 1,573
  • 7
  • 41
  • 54
0
votes
1 answer

How show image from bytes?

Error Compiler Error Message: CS1502: The most appropriate method to overload 'System.Web.WebPages.WebPageExecutingBase.Write (System.Web.WebPages.HelperResult)' has some invalid arguments @ImageResultHelper.Image(c =>…
den den
  • 469
  • 2
  • 6
  • 9
0
votes
0 answers

Is it possible to return a FileContentResult with StatusCode = 400 in ASP.NET?

I have an endpoint that receives a spreadsheet and call a service to read and process this spreadsheet. And i would like to return this spreadsheet if I find some inconsistency or error (with some correction indications). But how can I do to return…
FeGo
  • 1
0
votes
1 answer

My ASP.NET Core MVC controller method is supposed to return an Excel file with data, but it is empty

Here is my code: public IActionResult DownloadMyFile(int Id) { var fileData = // Service call to get data using (var workbook = new XLWorkbook()) { var worksheet = workbook.AddWorksheet("data"); var columnNames =…
0
votes
1 answer

FileContentResult encoding issue with Sharepoint file by Azure Function

I am facing en enconding issue when downloading a file from Sharepoint Online by an Azure function. So I have an Azure HTTP triggered function that calls Sharepoint Online to retrieve a file and download it. Here is how I call Sharepoint: public…
Hubert Solecki
  • 2,611
  • 5
  • 31
  • 63
0
votes
2 answers

Html.RenderAction with FileContentResult

With MVC3, I have a controller that returns a FileContentResult, which is a JPEG. I can call this and it displays the JPEG perfectly in the browser. I would like to display this multiple times on the page and the only reasonable way I can think of…
Bobbler
  • 633
  • 1
  • 7
  • 21
0
votes
1 answer

MVC3 Download Excel Workbook from CSV data

I've got a set of data that exists in memory in a CSV format. I have this method in my controller: public FileContentResult ItemsAsExcelExport(){ var model = _itemService.GetExcelExportModel(); return new…
Jeff Reddy
  • 5,551
  • 9
  • 55
  • 88
0
votes
2 answers

FileContentResult return excel file corrupt

I am trying to download an xlsx file from an ftp but when I download and try to open it I get that it is a corrupt file. . I share the back and front code. public async Task DownloadFileInterface(Uri serverUri, string fileName) { …
0
votes
1 answer

file not downloading on ajax post response .net core

i am facing problem on file response , its not downloading file, please check following code containing controller method and Ajax post call, the object there is to input an excel file from user on the form, read and calculate the data on conditions…
0
votes
0 answers

How can I consume a FileContentResult returned from an .Net Core api inside a .Net WebApi?

I am trying something similar posted [here][1] [1]: .Net Core Receive FileContentResult from one API to Another This is what I am trying and I think I am very close,just that not sure how to receive the in the receiver Api a response which is…
user2948533
  • 1,143
  • 3
  • 13
  • 32
0
votes
1 answer

Why is RestSharp RestClient ExecuteAsync returning *Data at the root level is invalid. Line 1, position 1.*?

I'm calling a microservice API using RestSharp with a POST message in a RestClient ExecuteAsync call for testing purposes. The data is coming back null and an error message is being returned as Data at the root level is invalid. Line 1, position…
BermudaLamb
  • 273
  • 3
  • 5
  • 24
0
votes
1 answer

How to download a file via an ActionResult method?

I have this controller endpoint where an form can be submitted, and and in case a specific form is being is being used it should "autodownload" a file generated based on the input provided from the user. How do I go about this? I have tried this …
0
votes
0 answers

In .NET Core is there a specific way to prevent this file content log from being written as-is?

I'm using a JSON log sink which destructures complex properties. For some reason, Microsoft has this log built-in when you return a file content result from your controller action: Executing {FileResultType}, sending file with download name…
user15716642
  • 171
  • 1
  • 12