Downloading files from a database to Asp.Net Mvc

I store my files in a database and should load the file at the click of a button.
I can get the contents of the file (Binary) in the action method. But how to return it as a file to the user?

+5
source share
2 answers
<%= Html.ActionLink("download file", "download") %>

and in your action:

public ActionResult Download() 
{
    byte[] contents = GetFileContentsFromDatabase();
    return File(contents, "image/jpeg")
}
+13
source
return new FileContentResult(byte[], contentType)
+2
source

All Articles