I have a requirement to export a dataset as a CSV file.
I have spent a while searching for a set of rules to go by and realised there are quite a few rules and exceptions when writing a CSV file.
http://knab.ws/blog/index.php?/archives/3-CSV-file-parser-and-writer-in-C-Part-1.html http://bytes.com/topic/c-sharp/answers/236875-problems-streamwriter-output-csv http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/0073fcbb-adab-40f0-b768-4bba803d3ccd
So now it is not a simple process of separating strings with commas, I have searched for an existing CSV writer either 3rd party or (hopefully!) included in the .net framework.
Edit: New link: http://www.thinqlinq.com/Post.aspx/Title/LINQ-to-CSV-using-DynamicObject-and-TextFieldParser
The TextFieldParser is a VB object (can be referenced from C#) that will automatically parse CSV files. :)
I was wondering if anybody knows any handy .Net (2.0 -> 3.5 and 4.0) libraries that can be used to generate a correctly formatted CSV file.
Also, if there are any sets of rules for generating CSV files.
There are a lot of details of CSV readers and parsing CSV files, however not as many about writing (ok, I know it is just the opposite :P ).
http://www.codeproject.com/KB/database/CsvReader.aspx
Any help would be much appreciated :)
I found another article with some more detailed CSV rules: http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm
A neat 3rd party library is Linq-to-CSV (not framework library): http://www.codeproject.com/KB/linq/LINQtoCSV.aspx
Thanks for your help everyone. I have decided that the best solution will be to create a simple static class that will do the special character replacement (that Chris mentioned).
If I had a need for Linq querying my CSV files, I would look at the CodeProjects implementation of Linq-to-CSV.
Thanks again :)