Empty file with MVC file download
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开发者_Python百科 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.
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);
精彩评论