AlphaCSV 1.0.0-alpha0

This is a prerelease version of AlphaCSV.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package AlphaCSV --version 1.0.0-alpha0
                    
NuGet\Install-Package AlphaCSV -Version 1.0.0-alpha0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AlphaCSV" Version="1.0.0-alpha0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AlphaCSV" Version="1.0.0-alpha0" />
                    
Directory.Packages.props
<PackageReference Include="AlphaCSV" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AlphaCSV --version 1.0.0-alpha0
                    
#r "nuget: AlphaCSV, 1.0.0-alpha0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AlphaCSV@1.0.0-alpha0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AlphaCSV&version=1.0.0-alpha0&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=AlphaCSV&version=1.0.0-alpha0&prerelease
                    
Install as a Cake Tool

AlphaCSV

A small .net 6 library that reads and writes CSV files. The goal of this library is to help anyone who makes small automation or migration projects. It can however be used in larger projects.

The library imports the CSV into a datatable. The columns of the datatable can have multiple types which can be described in a datatable schema.

This library can also parse CSV files into lists of classes or records provided that:

  1. They provide public parameterless constructors
  2. Have public set properties

Before Proceeding

This library is released as is and is still in <b>ALPHA</b> state. I am not reponsible for any issues or possible data loss that may occur with the use of this library.

Installation

In order to use the library just install the nuget package from nuget.org.

Usage

Just include the following line in the start of your program or in your global usings.

using AlphaCSV;

Parsing of a simple file

A simple csv file such as the following:

ColumnA,ColumnB
Row1,ValA
Row2,ValB
Row3,ValC

Can be parsed as follows:

CSVParser parser = new CSVParser();
DataTable result = parser.ParseSimpleCSV(filename);

Note: The above method will produce a datatable whose columns will be of string type.

Defining types on the DataTable columns.

Sometimes you may need a more complex file to parse. A file where you might need a different schema. This function can be performed with the ParseDefinedCSV method.

For example for a file like this:

ColumnA,ColumnB
Row1,1
Row2,3
Row3,5
DataTable schema = new DataTable();
schema.Columns.Add(new DataColumn("ColumnA", typeof(string)));
schema.Columns.Add(new DataColumn("ColumnB", typeof(int)));

CSVParser parser = new CSVParser();
DataTable result = parser.ParseDefinedCSV(schema, filename);

The CSV file is then parsed into a datatable. Note that the schema of the file has to be defined, both in terms of column names and also in terms of type.

Parsing custom types with the ParseType<T> method.

If you have custom types then those could be parsed as the following example: For a record

public record Person {
	public string Name { get; set; }
	public string Surname { get; set; }
}

A CSV file could can be parsed as follows:

CSVParser parser = new CSVParser();
List<Person> persons = parser.ParseType<Person>(filepath);

Of course the CSV file should have the following form

Name,Surname
John,Doe
Jane,Doe

The column ordering does not matter as long as the correct property names are given. The following file is just as valid:

Surname,Name
Doe,John
Doe,Jane

The CSVParseOptions Class

This class controls the behavior of the csv parser and may be passed to the parser method as an optional argument.

The options can be set through the public properies of the class. The parameters that can be controlled are the following :

  • The Delimeter. This is the character that seperates the fields within the file. (Default value of ,).
  • The CommentCharacter. Every line that starts with this character is ignored. (Default value of #).
  • The QuoteCharacter. This is the character that escapes a field if that field contains the Delimerer character.
  • The CheckHeaders indicates to the parser if it must validate the file headers against a schema. (Default false). This does not apply for the ParseType method as it always checks for the correct names.
  • The ValidateFields indicates to the parser if it must validate the field values against a provided regular expression (Default false).
  • The DateTimeFormat indicates to the parser the format of any DateTime that may be contained in the file. (Default is "").
  • The ContainsHeaders indicates if the CSV file has a header row. (Default value is false) note that this option is not taken into account when reading a defined CSV.
  • The AllowEmptyLastField Indicates wether the last field of the file lines can be empty. (eg when there is no data on the last field) Default true.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on AlphaCSV:

Package Downloads
libBOM

A package that handles BOM for internal tooling

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-beta.8 37 9/12/2026
1.0.0-beta.7 86 3/29/2026
1.0.0-beta.6 190 6/14/2025
1.0.0-beta.5 134 7/10/2024
1.0.0-beta.4 229 2/23/2023
1.0.0-beta.3 196 2/22/2023
1.0.0-beta.2 210 2/22/2023
1.0.0-beta.1 277 3/15/2022
1.0.0-beta.0 262 3/15/2022
1.0.0-alpha0 276 1/30/2022