Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc FileStreamResult

Tags:

asp.net-mvc

First part of question:

I have information in DB and I want to get it from db and save it as .txt file to client.

I have done it with Regular asp.net. but in mvc not yet. My information is not an image. This information about peoples

I watched to This site

Second part of question:

I want to download file to client. There is not problem when downloading one file, but I want to download 3 file at once time with 1 request. But it could not be done. So I decided to create zip file and generate link. When user will click to link it will download to user.

What you think? Is it good to do it with this way?

Third part of question:(new)

How i can delete old .zip files from catalog after succes download? or another way. Lets say with service which will run on server.

like image 379
AEMLoviji Avatar asked Jan 18 '11 13:01

AEMLoviji


1 Answers

You could have the following controller action which will fetch the information from the database and write it to the Response stream allowing the client to download it:

public ActionResult Download()
{
    string info = Repository.GetInfoFromDatabase();
    byte[] data = Encoding.UTF8.GetBytes(info);
    return File(data, "text/plain", "foo.txt");
}

and in your view provide a link to this action:

<%= Html.ActionLink("Downoad file", "Download") %>
like image 138
Darin Dimitrov Avatar answered Nov 15 '22 16:11

Darin Dimitrov