Thursday, January 15, 2015

Downloading Files in MVC where excel is not actually opened

I inherited from FileResult and it did not download - even though I set download name

I did this and it works

     public FileResult DownloadTextAsAFile(string data, string name)
        {
        string fileName = string.Format("{0}.csv", name);
        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
        return new FileContentResult(bytes, "application/vnd.ms-excel") { FileDownloadName = name };
        }

No comments:

Post a Comment