CSVFile 3.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package CSVFile --version 3.0.5                
NuGet\Install-Package CSVFile -Version 3.0.5                
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="CSVFile" Version="3.0.5" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSVFile --version 3.0.5                
#r "nuget: CSVFile, 3.0.5"                
#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.
// Install CSVFile as a Cake Addin
#addin nuget:?package=CSVFile&version=3.0.5

// Install CSVFile as a Cake Tool
#tool nuget:?package=CSVFile&version=3.0.5                

NuGet Travis (.com)

csharp-csv-reader

This library is a series of unit tested, thoroughly commented CSV parsing functions which I have developed off and on since 2006. Extremely small and easy to implement; includes unit tests for the majority of odd CSV edge cases. Library supports different delimiters, qualifiers, and embedded newlines. Can read and write from data tables.

Why use CSharp CSV Reader?

A few reasons:

  • Version 3.X of CSVFile provide compatibility to C# 4.0; versions 2.X provide compatibility all the way back to C# 2.0. Makes it easy to integrate this library into extremely old legacy projects.
  • Between 16-32 kilobytes in size, depending on framework.
  • No dependencies.
  • Handles all the horrible edge cases from poorly written CSV generating software: custom delimiters, embedded newlines, and doubled-up text qualifiers.
  • Reads via streams, optionally using asynchronous I/O. You can parse CSV files larger than you can hold in memory without thrashing.

Tutorial

Want to get started? Here are a few walkthroughs.

Custom CSV Settings

Do you have files that use the pipe symbol as a delimiter, or does your application need double quotes around all fields? No problem!

var settings = new CSVSettings()
{
    FieldDelimiter = '|',
    TextQualifier = '\'',
    ForceQualifiers = true
};
s = array.ToCSVString(settings);

Streaming asynchronous CSV

The latest asynchronous I/O frameworks allow you to stream CSV data off disk without blocking. Here's how to use the asynchronous I/O features of Dot Net 5.0:

using (var cr = await CSVAsyncReader.from(stream, settings)) {
    await foreach (string[] line in cr) {
        // Do whatever you want with this one line - the buffer will
        // only hold a small amount of memory at once, so you can 
        // iterate at your own pace!
    }
}

Streaming CSV without async

Don't worry if your project isn't yet able to use asynchronous foreach loops. You can still use the existing reader logic:

using (CSVReader cr = new CSVReader(sr, settings)) {
    foreach (string[] line in cr) {
        // Process this one line
    }
}

Serialize and Deserialize

You can serialize and deserialize between List<T> and CSV arrays. Serialization supports all basic value types, and it can even optionally support storing null values in CSV cells.

var list = new List<MyClass>();

// Serialize an array of objects to a CSV string
string csv = CSV.Serialize<MyClass>(list);

// Deserialize a CSV back into an array of objects
var newlist = await CSV.Deserialize<MyClass>(csv);

Data Table Support (for older DotNet frameworks)

For those of you who work in older frameworks that still use DataTables, this feature is still available:

// This code assumes the file is on disk, and the first row of the file
// has the names of the columns on it
DataTable dt = CSV.LoadDataTable(myfilename);

// Save a datatable to a file
dt.SaveAsCSV(myfilename, true);

Hand Roll Your Own

The class CSV contains a lot of useful functions for hand rolling your own CSV related code. You can use any of the functions in the CSV class directly.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on CSVFile:

Package Downloads
AllaganLib.Data

Package Description

LuminaSupplemental.Excel

Supplemental data for lumina and dalamud plugins.

AllaganLib.GameSheets

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.2.0 17,933 8/6/2024
3.1.4 114 8/5/2024 3.1.4 is deprecated because it has critical bugs.
3.1.3 112 8/5/2024 3.1.3 is deprecated because it has critical bugs.
3.1.2 33,929 7/19/2023 3.1.2 is deprecated because it has critical bugs.
3.1.1 34,118 3/18/2023
3.1.0 19,512 4/4/2022
3.0.9 974 3/23/2022
3.0.8 564 3/23/2022 3.0.8 is deprecated.
3.0.7 4,603 3/16/2022
3.0.6 20,581 3/7/2022
3.0.5 481 3/2/2022
3.0.4 970 2/15/2022
3.0.3 539 2/11/2022
3.0.2 9,635 4/9/2021
3.0.1 451 4/9/2021
2.0.3 39,877 10/30/2018
1.2.2.2 25,168 11/18/2016
1.2.2 1,597 11/4/2016
1.2.2-beta 1,239 11/4/2016
1.2.1 1,513 8/1/2016

Improved compatibility with multiple versions of the Dot Net framework.
* Version 3.0.5 builds for Dot Net 4.0, 4.5, Net Standard 2.0, Net Core 3.1, 5.0, and 6.0
* Some improvements on compiler warnings
* Included XML documentation with modern Dot Net Core versions