how to use csvHelper to read the second line in a csv file

The accepted answer is a workaround for the problem, but the library has the first-class solution for this common case
CsvConfiguration class has a property HasHeaderRecord which could be set to true, this will cause the library to skip the first line in the file.

CsvConfiguration configuration = new CsvConfiguration { HasHeaderRecord = true };

using (TextReader sr = new StringReader(fileContent))
{
    CsvReader reader = new CsvReader(sr, configuration);
}

here is a snippet of the Documentation

Gets or sets a value indicating if the CSV file has a header record. Default is true.

UPDATE in the newer version of the library the class CsvConfiguration is just renamed to Configuration


You could use TextReader.ReadLine() to skip the first line:

using (TextReader reader = File.OpenText("filename"))
{
    reader.ReadLine();
    // now initialize the CsvReader
    var parser = new CsvReader( reader ); // ...
}

Tags:

C#

Csv

Csvhelper