DbfSharp.Core
0.2.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package DbfSharp.Core --version 0.2.3
NuGet\Install-Package DbfSharp.Core -Version 0.2.3
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="DbfSharp.Core" Version="0.2.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbfSharp.Core" Version="0.2.3" />
<PackageReference Include="DbfSharp.Core" />
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 DbfSharp.Core --version 0.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DbfSharp.Core, 0.2.3"
#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 DbfSharp.Core@0.2.3
#: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=DbfSharp.Core&version=0.2.3
#tool nuget:?package=DbfSharp.Core&version=0.2.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DbfSharp.Core
A high-performance, memory-efficient DBF (dBase) file reader for .NET with support for all major DBF versions and memo files.
Installation
dotnet add package DbfSharp.Core
Features
- Support for all major DBF versions (dBase III, IV, Visual FoxPro, etc.)
- High performance with streaming and loaded access patterns
- Memory efficient streaming by default, optional loading for random access
- Full memo file support (FPT, DBT files) for large text and binary data
- Plugin architecture for custom field parsers
- Modern C# with Span<T>, Memory<T>, and latest .NET features
- Support for all standard field types and character encodings
Quick Start
Basic Usage
using DbfSharp.Core;
// Open and read a DBF file
using var reader = DbfReader.Open("data.dbf");
foreach (var record in reader.Records)
{
var name = record.GetValue<string>("NAME");
var birthDate = record.GetValue<DateTime?>("BIRTHDATE");
var salary = record.GetValue<decimal?>("SALARY");
Console.WriteLine($"{name}, born {birthDate}, salary: {salary:C}");
}
Async Operations
// Async file operations
using var reader = await DbfReader.OpenAsync("data.dbf");
await foreach (var record in reader.ReadRecordsAsync())
{
var name = record.GetValue<string>("NAME");
Console.WriteLine($"Processing: {name}");
}
Performance Optimized
// Use performance-optimized settings for large files
var options = DbfReaderOptions.CreatePerformanceOptimized();
using var reader = DbfReader.Open("large_file.dbf", options);
foreach (var record in reader.Records)
{
var id = record[0]; // Access by index for speed
var name = record["NAME"]; // Access by name
}
Memory Optimized
// Use memory-optimized settings for huge files
var options = DbfReaderOptions.CreateMemoryOptimized();
using var reader = DbfReader.Open("huge_file.dbf", options);
// Process one record at a time with minimal memory usage
foreach (var record in reader.Records)
{
ProcessRecord(record);
}
Loaded Mode for Analysis
// Load all records into memory for random access
using var reader = DbfReader.Open("analysis.dbf");
reader.Load();
// Access records by index
var firstRecord = reader[0];
var lastRecord = reader[reader.Count - 1];
// Use LINQ for queries
var highSalaries = reader.Records
.Where(r => r.GetValue<decimal?>("SALARY") > 50000)
.ToList();
Configuration
DbfReaderOptions
var options = new DbfReaderOptions
{
Encoding = Encoding.UTF8, // Override auto-detected encoding
IgnoreCase = true, // Case-insensitive field names
LowerCaseFieldNames = false, // Convert field names to lowercase
LoadOnOpen = false, // Load all records immediately
IgnoreMissingMemoFile = true, // Don't fail if memo file missing
TrimStrings = true, // Trim whitespace from strings
ValidateFields = false, // Skip field validation for speed
MaxRecords = 10000, // Limit number of records read
BufferSize = 64 * 1024, // I/O buffer size
UseMemoryMapping = true // Use memory-mapped files (64-bit)
};
using var reader = DbfReader.Open("data.dbf", options);
Preset Configurations
// Maximum performance
var perfOptions = DbfReaderOptions.CreatePerformanceOptimized();
// Minimum memory usage
var memOptions = DbfReaderOptions.CreateMemoryOptimized();
// Maximum compatibility
var compatOptions = DbfReaderOptions.CreateCompatibilityOptimized();
Supported Field Types
DBF Type | .NET Type | Description |
---|---|---|
C | string | Character/Text |
D | DateTime? | Date (YYYYMMDD) |
F | float? | Floating point |
I | int | 32-bit integer |
L | bool? | Logical (T/F/Y/N/?) |
M | string | Memo (variable length text) |
N | decimal? | Numeric (integer or decimal) |
O | double | Double precision float |
T, @ | DateTime? | Timestamp |
Y | decimal | Currency |
B | varies | Binary (memo or double depending on version) |
G | byte[] | General/OLE object |
P | byte[] | Picture |
V | string | Varchar |
+ | int | Autoincrement |
0 | byte[] | Flags |
Advanced Features
Custom Field Parsers
public class CustomFieldParser : FieldParserBase
{
public override bool CanParse(FieldType fieldType, DbfVersion dbfVersion)
{
return fieldType == FieldType.Character;
}
public override object? Parse(DbfField field, ReadOnlySpan<byte> data,
IMemoFile? memoFile, Encoding encoding, DbfReaderOptions options)
{
// Custom parsing logic
var text = encoding.GetString(data);
return text.ToUpperInvariant(); // Example: convert to uppercase
}
}
var options = new DbfReaderOptions
{
CustomFieldParser = new CustomFieldParser()
};
Error Handling
try
{
using var reader = DbfReader.Open("data.dbf");
foreach (var record in reader.Records)
{
// Check for invalid values
foreach (var kvp in record)
{
if (kvp.Value is InvalidValue invalid)
{
Console.WriteLine($"Invalid value in field {kvp.Key}: {invalid.ErrorMessage}");
}
}
}
}
catch (DbfNotFoundException ex)
{
Console.WriteLine($"File not found: {ex.FilePath}");
}
catch (MissingMemoFileException ex)
{
Console.WriteLine($"Memo file missing: {ex.MemoFilePath}");
}
catch (FieldParseException ex)
{
Console.WriteLine($"Parse error in field {ex.FieldName}: {ex.Message}");
}
Working with Deleted Records
var options = new DbfReaderOptions
{
SkipDeletedRecords = false // Include deleted records
};
using var reader = DbfReader.Open("data.dbf", options);
// Access only deleted records
await foreach (var deletedRecord in reader.ReadDeletedRecordsAsync())
{
Console.WriteLine($"Deleted Record ID: {deletedRecord.GetValue<int>("ID")}");
}
Metadata and Statistics
using var reader = DbfReader.Open("data.dbf");
var stats = reader.GetStatistics();
Console.WriteLine($"Table: {stats.TableName}");
Console.WriteLine($"Version: {stats.DbfVersion}");
Console.WriteLine($"Records: {stats.TotalRecords:N0}");
Console.WriteLine($"Fields: {stats.FieldCount}");
Console.WriteLine($"Encoding: {stats.Encoding}");
Console.WriteLine($"Last Updated: {stats.LastUpdateDate}");
// Inspect field definitions
foreach (DbfField field in reader.Fields)
{
Console.WriteLine($"- {field.Name} ({field.Type}), Length: {field.ActualLength}");
}
Performance
Optimization Tips
- Use streaming for large files (don't call
Load()
unless you need random access) - Adjust buffer size for better I/O performance
- Use memory mapping for large files on 64-bit systems
- Limit record count with
MaxRecords
for sampling large files
Benchmarks
TBD
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- System.Text.Encoding.CodePages (>= 9.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.