Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 255
anonymous Avatar asked Dec 07 '25 10:12

anonymous


2 Answers

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

like image 72
Kevin Buchan Avatar answered Dec 10 '25 00:12

Kevin Buchan


FileHelpers will do what you ask with the FieldQuoted attribute on your field in the record mapping class.

like image 22
Forgotten Semicolon Avatar answered Dec 10 '25 02:12

Forgotten Semicolon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!