Sooraj
Sooraj

Reputation: 17

How can we read csv file in asp.net core using CsvHelper?

how to read and write csv file in asp.net core using CsvHelper

Upvotes: 1

Views: 3330

Answers (1)

Jonathan Wood
Jonathan Wood

Reputation: 67195

Are you asking how to write the code? Have you looked at the examples online?

Note that SoftCircuits.CsvParser is about four times faster than CsvHelper for some operations. Here's what it would look like to read a file using SoftCircuits.CsvParser:

string[] columns = null;
using (CsvReader reader = new CsvReader(path))
{
    while (reader.ReadRow(ref columns))
    {
        // Here columns contains an array of string values that
        // were read from the current line
    }
}

Note that both libraries also have the ability to map the columns directly to object properties so you can just create your class that has a property corresponding to each column, and everything will be mapped for you. The example above simply reads the columns as an array of strings.

Upvotes: 1

Related Questions