How to check CSV in C #?

Is there a built-in method in .NET that checks csv files / lines?

I would prefer something like this csv online validator , but in C #. I did some research, but all I found are examples of how people write the code itself (examples were written several years ago and may be outdated). A.

POC:

bool validCSV = CoolCSV_ValidatorFunction(string csv/filePath); 
+8
c # csv
source share
3 answers

There is! For some reason, it is buried in the VB namespace, but it is part of the .NET Framework, you just need to add a reference to the Microsoft.VisualBasic assembly. The type you are looking for is TextFieldParser .

Here is an example of checking your file:

 using Microsoft.VisualBasic.FileIO; ... var path = @"C:\YourFile.csv"; using (var parser = new TextFieldParser(path)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); string[] line; while (!parser.EndOfData) { try { line = parser.ReadFields(); } catch (MalformedLineException ex) { // log ex.Message } } } 
+12
source share

The best CSV reader I've found is Lumenworks:

http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader

Very fast, very full featured. Recommended.

+2
source share

This CSV Parser also seems promising (but not built-in): http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader

Related topic: CSV to .NET Mapping Options

+1
source share

All Articles