Table of Contents

Getting Started

Installation

Install FlameCsv using the NuGet package manager:

dotnet add package FlameCsv

Basic Usage

Reading CSV data is as simple as:

// Reading from a string
IEnumerable<User> users = CsvReader.Read<User>("id,name\n1,John\n2,Jane");

// Reading from a file
await foreach (var user in CsvReader.ReadAsync<User>(File.OpenRead("users.csv"))
{
    Console.WriteLine(user.Name);
}

Writing CSV is just as easy:

var users = new[]
{
    new User { Id = 1, Name = "John" },
    new User { Id = 2, Name = "Jane" }
};

// Writing to a string
StringBuilder csv = CsvWriter.WriteToString(users);

// Writing to a file
await CsvWriter.WriteToFileAsync("users.csv", users, cancellationToken);

Configuration

FlameCsv is highly configurable. Common options include:

Example of custom configuration:

var options = new CsvOptions<char>
{
    Delimiter = ';',    // Use semicolon as separator
    Quote = '"',        // Use double quotes
    Whitespace = " \t", // Trim spaces and tabs
    HasHeader = true,   // First line contains the header
};

var users = CsvReader.Read<User>(csv, options);

Next Steps