Reputation: 32490
I need to create a CSV file in C#
I could do this myself and I have a java utility I wrote to do this as a reference. However it would be easier to use an existing .net library or utility. Do any such libraries/utilities exists?
Upvotes: 2
Views: 962
Reputation: 23383
There are a few libraries that will help with writing. CsvHelper (a library I maintain) can take your objects and write them to a CSV file automatically for you.
var myCustomObjects = new List<MyCustomObject>{ ... };
var csv = new CsvHelper( File.OpenWrite( "file.csv" ) );
csv.Writer.WriteRecords( myCustomObjects );
Upvotes: 1
Reputation: 26829
Even though the question is pretty, I think it is worth adding information about CsvHelper library.
CsvHelper is a library for reading and writing CSV files. Extremely fast, flexible, and easy to use
2.0
, 3.5
, 4.5
Upvotes: 1
Reputation: 25810
Usually the problems lie with the reading/parsing of the CSV; writing/creating is more straightforward.
I shall not re-invent the wheel, here's a sample: A simple CSV generator from Dataset in C#
Upvotes: 1
Reputation: 50273
Take a look at this: http://www.codeproject.com/KB/aspnet/ExportClassLibrary.aspx
Upvotes: 2