1

Possible Duplicate:
How to create file and return it via FileResult in ASP.NET MVC?

ASP.NET MVC2: How to return a file from a controller?

I want to do this so the user can download the file from server.

Community
  • 1
  • 1
user469652
  • 48,855
  • 59
  • 128
  • 165
  • Possible duplicate of http://stackoverflow.com/questions/1375486/how-to-create-file-and-return-it-via-fileresult-in-asp-net-mvc *Hint*: `FileResult` is what you're looking for. – Klemen Slavič Nov 23 '10 at 13:19

1 Answers1

1
        public ActionResult Csv(int pid)
        {
            var csv = this.Repo.GetCsv(pid);
            var fileContents = Encoding.GetEncoding(1251).GetBytes(csv);
            return new FileContentResult(fileContents, "application/vnd.ms-excel") { FileDownloadName = "Report-" + pid + ".csv" };
        }

The Smallest
  • 5,713
  • 25
  • 38