
Here you have a byte array and want to return byte content as a file.īelow are a few examples of MIME – content types for your information. Here you have a stream and want to return stream content as a file.įileContentResult – Sends the contents of a binary file to the response.

Both FileContentResult & FileStreamResult classes are derived class from Abstract FileResult class.įileStreamResult – Sends binary content to the response by using a Stream instance. Return File(stream, “application/”, “FileasStream.xlsx”) ĭifference between FileContentResult and FileStreamResultĪs we know FileResult is an abstract base class. Please see the below example to achieve the same. You cal also use the File class for file processing. Return new FileContentResult(byteArr, mimeType) Public async Task DownloadfromBytes(string id)īyte byteArr = _fileInterafces.ReadAsByteStream(id) jpg etc.įor png file we need to use mimeType = “image/png.

Using the below technique controller can return any other types of images like. Here we will be returning an image from the Controller method. Here you have a stream and want to return stream content as a file.ĭownload or Return Image (.png) file in. Using FileStreamResult for File DownloadįileStreamResult classes us useful for Sending binary content. These methods are coming from the FileResult abstract class and give you multiple options for retrieving files to send to the client.ġ. The file helper method is built into your controller.
#DOWNLOAD ASPX FILE FROM WEBSITE DOWNLOAD#
This file download or return technique can be used for any ASP.NET Core, Angular app.
#DOWNLOAD ASPX FILE FROM WEBSITE HOW TO#
We shall see how to perform a download or file return in ASP.NET core-based application. Most of the time, we get requirements to download or return the file within the given ASP.NET Core or Angular or any other UI applications dealing with it. We will use ASP.NET Core WebAPI as a sample to verify how to download Files in ASP.NET Core-based API or MVC application.

xlsx, etc in the browser or any other type of application. In this article, we will see how to Return or Download File in ASP.NET Core API. Return or Download File in ASP.NET Core API
