views:

30

answers:

1

Related to my previous question on this matter, where the file was not being produced, the file returned by the following code is now empty. My controller action is declared as follows, then has a body that generates CSV lines from records for export. The CSV generation works.

[Authorize(Order = 0, Roles = "Requester,Controller,Installer")]
public FileStreamResult ExportJobCards()

In the following code that should return a populated CSV file, lines is of type List<string> and has 126 items. sw.BaseStream has the value 770048 for both its Length and Position properties. A zero byte file is returned to the browser, however.

+1  A: 

Make sure to "rewind" the stream before you return it in the result. I think something like the following this would work:

sw.BaseStream.Seek(0, SeekOrigin.Begin);

Smashd
That was exactly it, thanks!
ProfK