1

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

2

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.