Reading and Writing CSV with ASP.NET Core


is what I use to manage CSV in my ASP.NET Core projects.

How to read CSV

using (var reader = new StreamReader(file.OpenReadStream(), Encoding.GetEncoding("UTF-8")))
using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
   var records = csv.GetRecords<{YOUR MODEL HERE}>();

   foreach (var item in records)
       // Do something here.

When you prepare your class, you can go by name or where the column is.

public class Foo
    public int Id { get; set; }

    public string Name { get; set; }
Published: 2022-04-06