Tuesday, July 16, 2013

Read a very large csv files in C#

While csv file format is very simple (since it is just comma separate text file) and it is convenient to load csv file entirely into memory, for a very large csv file (e.g. those dumped from a large database). You will find that even tools such Microsoft Office Excel cannot open these files entirely. If you tried to load them into memory using .NET, you will probably end with "Out of memory" exception. In this case, you will find the CSVReader at http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader to be very useful. In my application, the reader has no problem loading millions of records which easily exceed 2GB in memory, although it reads line by line in a forward manner, which is fine in my case (as I use it to convert the CSV file to SQL database).

No comments:

Post a Comment