FileHelpers.Core
9.0.5
dotnet add package FileHelpers.Core --version 9.0.5
NuGet\Install-Package FileHelpers.Core -Version 9.0.5
<PackageReference Include="FileHelpers.Core" Version="9.0.5" />
<PackageVersion Include="FileHelpers.Core" Version="9.0.5" />
<PackageReference Include="FileHelpers.Core" />
paket add FileHelpers.Core --version 9.0.5
#r "nuget: FileHelpers.Core, 9.0.5"
#:package FileHelpers.Core@9.0.5
#addin nuget:?package=FileHelpers.Core&version=9.0.5
#tool nuget:?package=FileHelpers.Core&version=9.0.5
FileHelpers.Core
A powerful and easy-to-use .NET library for importing and exporting data from fixed-length or delimited files, strings, or streams.
Features
- Declarative Mapping: Use attributes to define file structure
- Multiple Formats: Support for CSV, fixed-length, and custom delimited formats
- Type Conversion: Automatic conversion between file data and .NET types
- Error Handling: Robust error management and validation
- Async Support: Asynchronous reading and writing for large files
- Performance: Optimized for speed and memory efficiency
Installation
dotnet add package FileHelpers.Core
Quick Start
Reading a CSV File
using FileHelpers.Core;
// Define your record class
[DelimitedRecord(",")]
public class Customer
{
public string Name { get; set; }
public string Email { get; set; }
public DateTime RegisterDate { get; set; }
}
// Read the file
var engine = new FileHelperEngine<Customer>();
var records = engine.ReadFile("customers.csv");
foreach (var customer in records)
{
Console.WriteLine($"{customer.Name} - {customer.Email}");
}
Writing to a File
var customers = new List<Customer>
{
new Customer { Name = "John Doe", Email = "john@example.com", RegisterDate = DateTime.Now },
new Customer { Name = "Jane Smith", Email = "jane@example.com", RegisterDate = DateTime.Now }
};
var engine = new FileHelperEngine<Customer>();
engine.WriteFile("output.csv", customers);
Fixed-Length Records
[FixedLengthRecord]
public class Product
{
[FieldFixedLength(10)]
public string SKU { get; set; }
[FieldFixedLength(30)]
public string Description { get; set; }
[FieldFixedLength(8)]
[FieldConverter(ConverterKind.Decimal)]
public decimal Price { get; set; }
}
Advanced Features
Custom Converters
[DelimitedRecord(",")]
public class Order
{
public int OrderId { get; set; }
[FieldConverter(typeof(MyCustomDateConverter))]
public DateTime OrderDate { get; set; }
}
Error Handling
var engine = new FileHelperEngine<Customer>();
engine.ErrorMode = ErrorMode.SaveAndContinue;
var records = engine.ReadFile("data.csv");
if (engine.ErrorManager.HasErrors)
{
foreach (var error in engine.ErrorManager.Errors)
{
Console.WriteLine($"Line {error.LineNumber}: {error.ExceptionInfo.Message}");
}
}
Async Reading
var engine = new FileHelperAsyncEngine<Customer>();
using (engine.BeginReadFile("large-file.csv"))
{
await foreach (var customer in engine.ReadNextAsync())
{
// Process each record
}
}
Supported Formats
- CSV - Comma-separated values
- TSV - Tab-separated values
- Fixed-Length - Fixed-width column files
- Custom Delimited - Any custom delimiter
- Multi-Record - Files with multiple record types
.NET Version Support
- .NET 9.0
- Built with modern C# features and performance optimizations
About This Fork
This is a maintained fork of the FileHelpers library, targeting .NET 9. The original FileHelpers library was created by Marcos Meli.
Why This Fork?
- Updated for .NET 9
- Maintained for modern .NET applications
- Compatible with latest C# features
- Active development and bug fixes
Documentation
For more examples and detailed documentation, visit:
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
MIT License - See LICENSE file for details
Original FileHelpers library: Copyright (c) Marcos Meli - Devoo
This fork: Maintained by RetailerSoft
Support
- Issues: https://github.com/retailersoft/FileHelpers.Core/issues
- Original Project: http://www.filehelpers.net
Examples
Skip Header Rows
[DelimitedRecord(",")]
[IgnoreFirst(1)] // Skip header row
public class DataRecord
{
public string Column1 { get; set; }
public string Column2 { get; set; }
}
Conditional Record Reading
var engine = new FileHelperEngine<Customer>();
var records = engine.ReadFile("data.csv")
.Where(c => c.RegisterDate > DateTime.Now.AddYears(-1));
Writing with Custom Header
var engine = new FileHelperEngine<Customer>();
engine.HeaderText = "Name,Email,Registration Date";
engine.WriteFile("output.csv", customers);
Performance Tips
- Use
FileHelperAsyncEnginefor large files - Set
ErrorMode.IgnoreAndContinueif you don't need error details - Consider using streaming for memory-intensive operations
- Cache engine instances when processing multiple files
Common Scenarios
Import Excel/CSV Data
Perfect for importing data from spreadsheets into your application.
Export Reports
Generate CSV files for reporting and data exchange.
Data Migration
Move data between systems using flat files.
ETL Operations
Extract, transform, and load data pipelines.
Log File Parsing
Parse structured log files into .NET objects.
FileHelpers.Core - Making file I/O simple and elegant for .NET developers! ??
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.CodeAnalysis.Common (>= 4.14.0)
- Microsoft.Data.SqlClient (>= 6.1.1)
- System.Data.OleDb (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
.NET 9 fork with README. Original: www.filehelpers.net/changelog