New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write csv file to string? #128
Comments
Yes. That is what most of the unit tests do... using( var stream = new MemoryStream() )
using( var reader = new StreamReader( stream ) )
using( var writer = new StreamWriter( stream ) )
using( var csv = new CsvWriter( writer ) )
{
csv.WriteRecords( events );
writer.Flush();
stream.Position = 0;
var text = reader.ReadToEnd();
} Or something similar. I did this from memory so not sure if it'll compile. ;) |
Thanks Josh, that did it. This is a great library! |
You're welcome. |
Found this via google and the answer is a bit old so thought I'd give it an update for anyone else who finds this.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to use the csvhelper to export a list of objects to a csv file in the browser. All I see in the documentation are ways to write directly to a file - can you return the csv file as a string for export?
I tried something like this, but the 'WriteRecords' method is closing the memory stream:
The text was updated successfully, but these errors were encountered: