Skip to content
DbfDataReader is a small fast .Net Core library for reading dBase, xBase, Clipper and FoxPro database files
C# PowerShell
Branch: master
Clone or download
dependabot and chrisrichards Bump CsvHelper from 7.1.1 to 9.2.3 (#25)
Bumps [CsvHelper](https://github.com/JoshClose/CsvHelper) from 7.1.1 to 9.2.3.
- [Release notes](https://github.com/JoshClose/CsvHelper/releases)
- [Commits](JoshClose/CsvHelper@7.1.1...9.2.3)

Signed-off-by: dependabot[bot] <support@dependabot.com>
Latest commit a0b41dd Nov 21, 2018

README.md

DbfDataReader

Build status NuGet MyGet Build Status

DbfDataReader is a small fast .Net Core library for reading dBase, xBase, Clipper and FoxPro database files

Usage, to get summary info:

var dbfPath = "path/file.dbf";
using (var dbfTable = new DbfTable(dbfPath))
{
    var header = dbfTable.Header;

    var versionDescription = header.VersionDescription;
    var hasMemo = dbfTable.Memo != null;
    var recordCount = header.RecordCount;

    foreach (var dbfColumn in dbfTable.Columns)
    {
        var name = dbfColumn.Name;
        var columnType = dbfColumn.ColumnType;
        var length = dbfColumn.Length;
        var decimalCount = dbfColumn.DecimalCount;
    }
}

and to iterate over the rows:

var skipDeleted = true;

var dbfPath = "path/file.dbf";
using (var dbfTable = new DbfTable(dbfPath))
{        
    var dbfRecord = new DbfRecord(dbfTable);

    while (dbfTable.Read(dbfRecord))
    {
        if (skipDeleted && dbfRecord.IsDeleted)
        {
            continue;
        }

        foreach (var dbfValue in dbfRecord.Values)
        {
            var stringValue = dbfValue.ToString();
            var obj = dbfValue.GetValue();
        }
    }
}

There is also an implementation of DbDataReader:

var options = new DbfDataReaderOptions
{
    SkipDeletedRecords = true
    // Encoding = EncodingProvider.GetEncoding(1252);
};

var dbfPath = "path/file.dbf";
using (var dbfDataReader = new DbfDataReader(dbfPath, options))
{
    while (dbfDataReader.Read())
    {
        var valueCol1 = dbfDataReader.GetString(0);
        var valueCol2 = dbfDataReader.GetDecimal(1);
        var valueCol3 = dbfDataReader.GetDateTime(2);
        var valueCol4 = dbfDataReader.GetInt32(3);
    }
}

which also means you can bulk copy to MS SqlServer:

var options = new DbfDataReaderOptions
{
    SkipDeletedRecords = true
    // Encoding = EncodingProvider.GetEncoding(1252);
};

var dbfPath = "path/file.dbf";
using (var dbfDataReader = new DbfDataReader(dbfPath, options))
{
    using (var bulkCopy = new SqlBulkCopy(connection))
    {
        bulkCopy.DestinationTableName = "DestinationTableName";

        try
        {
            bulkCopy.WriteToServer(dbfDataReader);
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error importing: dbf file: '{dbfPath}', exception: {ex.Message}");
        }
    }
}

Used by

You can’t perform that action at this time.