Blazor: CSV exported is empty
Hi, I'm using CsvHelper to export a list of objects to a csv and then make the use download, the file gets downloaded but it's empty.
5 Replies
First, you'd need to "reset" the memory stream after writing to it: memoryStream.Position = 0. Currently, the state of that stream is positioned at the end, since you just wrote data to it, so there are no bytes after the current position.
Second, you might run into issues because you aren't flushing/disposing anything. CsvWriter and even StreamWriter might have internal buffering that would prevent everything from arriving in the MemoryStream until they are flushed, or closed. Be aware, that disposing the StreamWriter will close the MemoryStream by default, there is a constructor overload that accepts a boolean to tell it to leave the stream open.
Still not working :/
Try this:
worked thanks, love you UwU