Skip to content

DotNet2Web/CsvCore

Repository files navigation


CsvCore

The only package you'll need to handle CSV files

About

What's this?

The CsvCore library is a .NET library that provides a simple and efficient way to read, write and validate CSV files. It is designed to be easy to use, flexible, and performant, making it an ideal choice for developers who need to work with CSV data in their applications.

What's so special about that?

No hassle, no fuss, no complexity but straight out of the box a working CsvCoreReader and CsvCoreWriter

Who created this?

My name is Tino Klijn, I'm a tech lead in the .NET environment.

During my years of development I encounter many libraries that support CSV handling, none of them matched my expectations. They lack missing documentation and therefore are too complex to use.

I strongly believe that a library should be easy to use and understand, otherwise what is the point of creating a package for you fellow devs.

So I decided to create my own library that is simple, easy to use and flexible.

Suggestions for improvements are always welcome. Please contact me to tell me your needs in the package or simply create an issue or pull request on GitHub.

How do I use it?

Easy, add the package to you project using the following command: dotnet add package csvcore or by using the NuGet package manager in your IDE. Then register the service in your IoC container:

builder.Services.AddScoped<ICsvCoreReader, CsvCoreReader>();

Then you can use the ICsvCoreReader in your code:

Example

CSV file

Name;Surname;Birthdate;Email
Foo;Bar;01/01/2025;foo@bar.com
public class Foo(ICsvCoreReader csvCoreReader)
{
    public void ReadWithHeaderRecordAndCustomDelimiter()
    {
         csvCoreReader.ForFile("yourFile.csv")
           .UseDelimiter(';') // Specify your custom delimiter.
           .HasHeaderRecord() // If the first row is a header, just tell us.
           .Read<ResultModel>(); // Read and map the data to your own model and yes the result is a IEnumerable of your model.
    }

    public void ReadWithoutHeaderRecordAndCustomDelimiter()
    {
         csvCoreReader.ForFile("yourFile.csv")
           .UseDelimiter(';') // Specify your custom delimiter.
           .Read<ResultModel>(); // Read and map the data to your own model and yes the result is a IEnumerable of your model.
    }

    public void ReadWithoutHeaderRecordAndDefaultDelimiter()
    {
         csvCoreReader.ForFile("yourFile.csv").Read<ResultModel>(); // Read and map the data to your own model and yes the result is a IEnumerable of your model.
    }
}
// The model should match the data in the CSV file.
public class ResultModel
{
    public string Name { get; set; }

    public string Surname { get; set; }

    public string Birthdate { get; set; }

    public string Email { get; set; }
}

Download

This library is available as a NuGet package on https://nuget.org. To install it, use the following command-line:

dotnet add package csvcore

Building

To build this repository locally, you need the following:

  • The .NET SDKs for .NET 8.0 and 9.0.
  • Visual Studio, JetBrains Rider or Visual Studio Code with the C# DevKit

You can also build, run the unit tests and package the code using the following command-line:

build.ps1

Or, if you have, the Nuke tool installed:

nuke

Also try using --help to see all the available options or --plan to see what the scripts does.

Contributing

Your contributions are always welcome! Please have a look at the contribution guidelines first.

Previous contributors include:

contrib.rocks image

(Made with contrib.rocks)

Versioning

This library uses Semantic Versioning to give meaning to the version numbers. For the versions available, see the tags on this repository.

Credits

This library wouldn't have been possible without the following tools, packages and companies:

Special thanks

Support the project

Coming soon

You may also like

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 2

  •  
  •