Search code examples
c#csvfilehelpers

Exporting to CSV - C#


I need to export a generic list to CSV. Obviously I could write my own, but would like to avoid this!

I am able to google and find a lot of CSV parsers, but not many writers. I have downloaded FileHelpers but it doesn't properly escape output.

For instance if a field is equal to

,,",,,

the output is simply:

,,",,,

For the field. I would expect:

",,"",,,"

correct?

Any suggestions, or should I just do it myself?


Solution

  • Check out RFC 4180. I had to write a XSL to convert XML to CSV and this made it very easy to know what the 'right' thing is to do.

    http://tools.ietf.org/rfc/rfc4180.txt