Import CSV file to strongly typed data structure in .Net

MattH picture MattH · Aug 5, 2008 · Viewed 66.5k times · Source

What's the best way to import a CSV file into a strongly-typed data structure?

Answer

MarkJ picture MarkJ · Apr 1, 2009

Microsoft's TextFieldParser is stable and follows RFC 4180 for CSV files. Don't be put off by the Microsoft.VisualBasic namespace; it's a standard component in the .NET Framework, just add a reference to the global Microsoft.VisualBasic assembly.

If you're compiling for Windows (as opposed to Mono) and don't anticipate having to parse "broken" (non-RFC-compliant) CSV files, then this would be the obvious choice, as it's free, unrestricted, stable, and actively supported, most of which cannot be said for FileHelpers.

See also: How to: Read From Comma-Delimited Text Files in Visual Basic for a VB code example.