CsvExport 3.0.1

dotnet add package CsvExport --version 3.0.1
                    
NuGet\Install-Package CsvExport -Version 3.0.1
                    
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="CsvExport" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CsvExport" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="CsvExport" />
                    
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 CsvExport --version 3.0.1
                    
#r "nuget: CsvExport, 3.0.1"
                    
#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 CsvExport@3.0.1
                    
#: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=CsvExport&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=CsvExport&version=3.0.1
                    
Install as a Cake Tool

CsvExport

A very simple and very fast CSV-export tool for C#.

.NET

V3 Breaking changes:

  • .NET 8 targeting (use v2 for .NET Framework, we'll backport critical fixes)
  • Uses char instead of string for column separator

Features

  1. Excel-compatible export (separator detected automatically, friendly-trimming rows and values for compatibility)
  2. Escapes commas, quotes, multiline text
  3. Exports dates in timezone-proof format
  4. Extremely easy to use
  5. 30 times faster than CsvHelper
  6. 4-times less memory usage

Benchmarks

Method Mean Error StdDev Gen0 Gen1 Allocated
😟 CsvHelper 372.90 us 390.842 us 21.423 us 9.7656 4.8828 85.4 KB
✅ CsvExport_Manual 12.71 us 1.040 us 0.057 us 3.5858 0.1984 29.35 KB
✅ CsvExport_GenericType 13.22 us 1.240 us 0.068 us 3.5858 0.2289 29.39 KB

This benchmark is generating a 100-line CSV file with 4 columns. Check the "SpeedBenchmarks" code.

Usage examples:

Install via Nuget Install-Package CsvExport

For "manual" CSV ad-hoc generation use this:

var myExport = new CsvExport();

myExport.AddRow();
myExport["Region"] = "Los Angeles, USA";
myExport["Sales"] = 100000;
myExport["Date Opened"] = new DateTime(2003, 12, 31);

myExport.AddRow();
myExport["Region"] = "Canberra \"in\" Australia";
myExport["Sales"] = 50000;
myExport["Date Opened"] = new DateTime(2005, 1, 1, 9, 30, 0);

///ASP.NET MVC action example
return File(myExport.ExportAsMemoryStream(), "text/csv", "results.csv");

For generating CSV out of a typed List<T> of objects:


public class Foo
{
	public string Region { get; set; }
	public int Sales { get; set; }
	public DateTime DateOpened { get; set; }
}

var list = new List<Foo>
{
	new Foo { Region = "Los Angeles", Sales = 123321, DateOpened = DateTime.Now },
	new Foo { Region = "Canberra in Australia", Sales = 123321, DateOpened = DateTime.Now },
};

var myExport = new CsvExport();
myExport.AddRows(list);
string csv = myExport.Export();

Configuring is done via constructor parameters:

var myExport = new CsvExport(
	columnSeparator: ",",
	includeColumnSeparatorDefinitionPreamble: true, //Excel wants this in CSV files
	includeHeaderRow: true
);

Also, methods ExportToFile and ExportAsMemoryStream and ExportToBytes offer an optional encoding parameter.

License

The code is licensed under MIT License.

Sucessfully tested for years in production with our Jitbit Helpdesk Ticketing System

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on CsvExport:

Repository Stars
RaythaHQ/raytha
Raytha is a powerful CMS with an easy-to-use interface and fast performance. It offers custom content types, a template engine, and various access controls. It supports multiple storage providers and an automatically generated REST API. Upgrade your development workflow with Raytha.
Version Downloads Last Updated
3.0.1 0 4/23/2026
3.0.0 0 4/22/2026
2.2.0 101,241 8/2/2025
2.0.1 165,640 6/6/2024
2.0.0 123,383 3/16/2023
2.0.0-beta 322 3/16/2023
1.0.3 114,464 10/4/2022
1.0.2 125,377 12/5/2021
1.0.1 212,840 10/11/2017