Take the 2-minute tour ×

Are there any CSV readers/writer libraries in C#?

share|improve this question

closed as not constructive by casperOne Jun 29 '12 at 3:15


7 Answers 7

Try CsvHelper. It's as easy to use as FastCsvReader and does writing also. I've been very happy with FastCsvReader in the past, but I needed something that does writing also, and wasn't happy with FileHelpers.


var csv = new CsvReader( stream );
var myCustomTypeList = csv.GetRecords<MyCustomType>();


var csv = new CsvWriter( stream );
csv.WriteRecords( myCustomTypeList );

Full Disclosure: I am the author of this library.

share|improve this answer

There are a couple of options, right in the framework itself.

One of the easiest is to Reference Microsoft.VisualBasic, then use TextFieldParser. It is a fully functional CSV reader in the core framework.

Another good alternative is to use datasets to read CSV files.

share|improve this answer
I always wondered why it was in the Microsoft.VisualBasic assembly... Did MS think that C# developers didn't use CSV ? –  Thomas Levesque Dec 21 '09 at 17:36
@Thomas: especially since a lot of C# developers cringe at the thought of including a VisualBasic assembly in their projects –  user195488 Dec 21 '09 at 17:42
Yeah - there are lots of nice "goodies" in there. I think it's more because VB has some language constructs that weren't really considered in the framework originally, but they would never have been able to get VB6 users across without implementing them. The Devices and ApplicationServices namespaces have all sorts of useful things. –  Reed Copsey Dec 21 '09 at 17:44
@Roboto,any C# developer that cringes at referencing Microsoft.VisualBasic in their project is an ignorant language snob. Even worse they don't understand .NET at all. –  Ash Dec 30 '09 at 2:18
Another VB assembly gem is CopyDirectory: stackoverflow.com/questions/58744/… –  user295190 Dec 19 '10 at 23:01

Sebastien Lorion has a great CSV reader on CodeProject called A Fast CSV Reader. Probably one of the best for C# and it's free.

As far as writing, just use StreamWriter!

Here is some boilerplate code for writing a DataGridView to file:

private void exportDGVToCSV(string filename)
        if(dataGridView1.Columns.Count != 0) {

            StringBuilder myString = new StringBuilder();

            if (File.Exists(FilePath + "file"))
                File.Delete(FilePath + "file");

            StreamWriter sw = new StreamWriter(filename, true);

            // loop through each row of our DataGridView

            foreach(DataGridViewRow row in dataGridView1.Rows) {
                foreach(DataGridViewCell cell in row.Cells) {               
                    myString.Append(cell.Value + ",");



share|improve this answer
This is my favourite. Great little library. –  Alex Dec 21 '09 at 17:24
but can't it write also? –  mrblah Dec 21 '09 at 17:25
Writing CSV is easy - just use a normal text output method, and separate by commas. You really only need a library/custom handler for reading... –  Reed Copsey Dec 21 '09 at 17:26
@Reed: it is not too trivial if you want to have commas and quotation marks escaped correctly. I'm not even sure if there is a standardization for this, but is is very common to do it. –  Stefan Steinegger Dec 21 '09 at 18:03
Writing CSV is a bit more complex than that. If the data you want expressed in the CSV file contains commas or new lines, you need to surround the data with quotation marks. If there's a quotation mark in the newly quotation-marked data, then you need to escape the quotation mark with double quotation marks. You could certainly code that logic yourself but it would be nice for a library to do it for you. –  Tinister Dec 21 '09 at 18:08

Yes - though I assume you're actually asking for specifics?

Try FileHelpers

share|improve this answer
Well, I did but for some strange reason FileHelpers broke down randomly. Furthermore, the FileHelpers library has not been in development for a long time. –  Erik Schierboom Feb 4 '11 at 9:02

There are dozens.

http://www.filehelpers.com/ is one of the most common.

I should say that I find Filehelpers restrictive in some scenarios, and instead use The Fast CSV Reader. In my experience, if you dont know the format of your CSV file or import mapping until runtime - this is the better library to use.

share|improve this answer
We use filehelpers also. –  Tangurena Dec 21 '09 at 17:37
I have found FileHelpers to be a nuisance to configure. FastCsvReader was a lot easier to use. –  Josh Close Jan 19 '10 at 16:12
+1 for FastCsvReader. Excellent performance. But it's a mainly a reader/parser. Not A writer. –  Mehdi LAMRANI Nov 23 '11 at 11:57

I wrote one and posted the source code and an article about it at http://www.blackbeltcoder.com/Articles/files/reading-and-writing-csv-files-in-c.

share|improve this answer
