views:

23

answers:

1
+1  Q: 

ASP MVC 2 Files

In controller, i create file. and invoke it by jquery.post. i understand that return file to view is impossible because of ajax. so i create file on disk, and return url of file to user. i think its not best way, but. my probleb now, is to know when user downloaded file, and delete it, how can i do it? or any others good ways to handle?

A: 

You don't have to use AJAX here. Just use a FileResult for the action that sends the file to the browser and the page content will not change.

public FileResult GetFile(int id)
{
    // generate file or initialize stream etc.

    return File("pathtofile", "text/plain"); // replace text/plain with the actual content type
    // alternative: return File(fileStream, "text/plain");
}
Dave