Its hidden inside "Microsoft.VisualBasic" namespace.
Below is a sample usage of the class and methods to read a file "Person.csv".
In the sample, the line commenting character is "#"; the delimiting character is ",".
The class exposes property to configure delimiting character (comma in our sample) and comment token (# in our sample).
Any field which are enclosed within double quotes will escape delimiting characters and double quotes within the data field. It beautifully handles with by just setting the HasFieldsEnclosedInQuotes property to true.
using Microsoft.VisualBasic.FileIO; var path = @"C:\Person.csv"; // Habeeb, "Dubai Media City, Dubai" using (TextFieldParser csvParser = new TextFieldParser(path)) { csvParser.CommentTokens = new string[] { "#" }; csvParser.SetDelimiters(new string[] { "," }); csvParser.HasFieldsEnclosedInQuotes = true; // Skip the row with the column names csvParser.ReadLine(); while (!csvParser.EndOfData) { // Read current line fields, pointer moves to the next line. string[] fields = csvParser.ReadFields(); string Name = fields[0]; string Address = fields[1]; } }
The parser has many more options. It can read a complete line as a single string. It can even read the remaining file content as a single string as well if needed in any case.
I will definitely rely on this parser rather than writing my own again.