Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading files from the database in Asp.Net Mvc

I'm storing my files in the database and need to download a file when button clicked.
i can get the File content (Binary) in the action method. But how to return it as a file to the user?

like image 267
CoffeeCode Avatar asked Mar 12 '10 15:03

CoffeeCode


1 Answers

<%= Html.ActionLink("download file", "download") %>

and in your action:

public ActionResult Download() 
{
    byte[] contents = GetFileContentsFromDatabase();
    return File(contents, "image/jpeg")
}
like image 180
Darin Dimitrov Avatar answered Sep 28 '22 06:09

Darin Dimitrov