CSV File Imports in .Net


Question

I realize this is a newbie question, but I'm looking for a simple solution - it seems like there should be one.

What's the best way to import a CSV file into a strongly-typed data structure? Again simple = better.

1
104
1/8/2013 12:44:51 PM

Accepted Answer

51
7/31/2015 1:26:51 PM

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.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon