Search Visual FoxPro compound indexes (.cdx)
mainYou can use CdxFile to open .cdx files and search for specific keys. The search results provide RecordIndex values (one-based) which can be converted to zero-based indices for use with DbfTable.Seek or DbfTable.Read.
using DbfDataReader.Cdx;
var dbfPath = "path/file.dbf";
var cdxPath = "path/file.cdx";
using (var dbfTable = new DbfTable(dbfPath))
using (var cdxFile = new CdxFile(cdxPath, dbfTable.CurrentEncoding))
{
var tagNames = cdxFile.TagNames; // the named indexes ("tags") in the file
var index = cdxFile.GetIndex("CONTACT_ID"); // one tag; index.KeyExpression describes the key
var dbfRecord = new DbfRecord(dbfTable);
foreach (var entry in index.Search("C0000000042"))
{
dbfTable.Seek(entry.RecordIndex);
dbfTable.Read(dbfRecord);
// dbfRecord now holds the matching row
}
}