0

I've got a set of data that exists in memory in a CSV format. I have this method in my controller:

     public FileContentResult ItemsAsExcelExport(){
         var model = _itemService.GetExcelExportModel();
        return new FileContentResult(model.CSVData, model.MimeType){FileDownloadName = model.FileName};
     }

The problem here is that my model.CSVData property returns a simple comma delimited set of values. I'm not sure how I can satisfy the fileContents argument of the FileContentResult contructor. It's asking for a byte array.

Thanks in advance.

Jeff Reddy
  • 5,365
  • 9
  • 48
  • 86

1 Answers1

1

Take a look at this question How do I get a consistent byte representation of strings in C# without manually specifying an encoding?

The solution is

  byte[] b1 = System.Text.Encoding.UTF8.GetBytes (myString); 
Community
  • 1
  • 1
Alleo
  • 6,116
  • 2
  • 32
  • 29