As we know FileResult is an abstract base class. FileStreamResult — Sends binary content to the response by using a Stream instance. Here you have a stream and want to return stream content as a file. FileContentResult — Sends the contents of a binary file to the response. Here you have a byte array and want to return byte content as a file.
Below are a few examples of MIME — content types for your information. Please bookmark this page and share this article with your friends and Subscribe to the blog to get a notification on freshly published best practices of software development. This article was helpful. I did write my custom interface in the above code which returns the stream and achieved the result. Hello James , Thanks for your query. I shall soon out the code on my GitHub. ReadAsStream id ;.
Hello Ben, Thanks for your query. You can create your own method which returns excel as stream and use as above. Net MVC Razor. Folder Directory Location. The Folder Directory is located within the Project. Below is the screenshot of the Solution Explorer window where you can see the Folder Directory i. Files and it containing three files. Following is a Model class named FileModel with one property i.
You will need to import the following namespace. The Controller consists of two Action methods. Action method for handling File Display operation. Later, the values of the Array are copied to a Generic List collection consisting objects of FileModel class and then returned to the View.
Action method for handling File Download operation. This action method handles the File Download operation and when the ActionLink is clicked, the name of the File to be downloaded is sent to this method. And then the Byte Array object is sent for download using the File function. GetFiles Server. ReadAllBytes path ;. Sample video link How to download files using asp.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to download a file in ASP. NET Core? Ask Question. Asked 4 years, 3 months ago. Active 1 month ago. Viewed k times. Response; System. ClearHeaders ; response. Clear ; response. BinaryWrite net.
DownloadData link ; response. End ;. Improve this question. Askolein 2, 2 2 gold badges 25 25 silver badges 36 36 bronze badges. Add a comment. Active Oldest Votes. Improve this answer.
Any Thoughts? The only way to solve this problem is by finding out the real error, which often is unrelated to business logic, much probably being a programming error like NullReferenceException or conversion between incompatible types, etc. Log files and debugging are some valid ways to troubleshot this kind of issue. I am downloading excel file. It downloads but when I try to open the file it says the file is corrupted. But when I download it is 10kb.
What kind of problem is this? This is an old answer, but my comment still applies.
0コメント