tags:

views:

4006

answers:

6

Hi,

is there a good and free implementation of CSV parser available under some liberal licence? Some counterpart of SuperCSV for Java, perhaps a port?

+19  A: 

http://www.filehelpers.com/

Keltex
+1 to it. Works great.
no_one
+1 werked awesome so simple to use. Like 4 lines of code.
Kieran
+12  A: 

There's a nice implementation on CodeProject:

To give more down to earth numbers, with a 45 MB CSV file containing 145 fields and 50,000 records, the reader was processing about 30 MB/sec. So all in all, it took 1.5 seconds! The machine specs were P4 3.0 GHz, 1024 MB.

Anton Gogolev
That's the one I tend to use... (+1)
Marc Gravell
Yeap used that myself, defo a quick tool
JustAPleb
Definitely the best one out for C#, it's really well designed as well
Chris S
Used this myself for several projects, and it's fast, easy to use and stable. I parse 100 mb with it each day at least. No problem recommending it.
simendsjo
+4  A: 

try filehelpers Work amazingly well. I am using it to parse a 100 MB file every day.

no_one
+3  A: 

Have you tried the FileHelpers library? It's free, open source and can be used to parse CSV files.

JaredPar
+1  A: 

I've started using CSV Parser that is part of the CommonLibrary.NET.

It uses .NET 3.5, has an easy API, and convenient overloads/methods & lamda's for iterations.

I don't have any benchmarks for this one like above, but nice thing about this is that it's just one component of a library similar to Java Commons. So I also get a Command-line parser, Repository implementation among other things.

zhao
+1  A: 

You can load a CSV file to DataTable.

Sample code -

static DataTable CsvToDataTable(string strFileName)
        {
            DataTable dataTable = new DataTable("DataTable Name");

            using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Directory.GetCurrentDirectory() + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\""))
            {
                conn.Open();
                string strQuery = "SELECT * FROM [" + strFileName + "]";
                OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(strQuery, conn);

                adapter.Fill(dataTable);
            }
            return dataTable;
        }

Make sure you compile your project to x86 processor. It doesn't work for x64.

Maxim
@Maxim: this worked pretty well for me since I wanted to stay with the built-in ODBC or OLEDB libraries. Btw, the following has additional code samples for both OLEDB and ODBC: http://www.csvreader.com/csv_benchmarks.php
Meringros