DBF Files
Jump to navigation
Jump to search
DBF File Links
FPT File Links
- https://go4answers.webhost4life.com/Example/read-fpt-file-binary-header-91321.aspx
- http://www.clicketyclick.dk/databases/xbase/format/fpt.html
The file format is used by Fox Pro 2.x and later The size of the header is 512 bytes
_______________________ _______ 00h / 0 | Number of next | ^ 00h / 1 | available block | | 00h / 2 | for appending data | Header 00h / 3 | (binary) *1| | |-----------------------| | 00h / 4 | ( Reserved ) | | 00h / 5 | | | |-----------------------| | 00h / 6 | Size of blocks N *1| | 00h / 7 | *2| | |-----------------------| | 00h / 8 | ( Reserved ) | | | | | | | | | (i.e. garbage) | | : : | : : | 00h / 511| | | |=======================| _v_____ 00h / 0| | ^ Used block | | | __ |=======================| | | | / 0| Record type *3| : : | / 1| *1| : : | / 2| | | | | / 3| | 00h / N| | | / |-----------------------| |=======================| _|_____/ 4| Length of memo field | 00h / 0| | | 5| *1| : : | 6| | : : | 7| | | | | |-----------------------| 00h / N| | _|_____ 8| Memo data | |=======================| | \ : : 0| | | \ N| | | | | \_____ |=======================| | | | : : | 00h / N| | _v_____ |=======================|
- Big-endian. Binary value with high byte first.
- Size of blocks in memo file (SET BLOCKSIZE). Default is 512 bytes.
Record type
Value Description 00h Picture. This normally indicates that file is produced on a MacIntosh, since pictures on the DOS/Windows platform are "objects". 01h Memo 02h Object
A memo field can be longer than the 512 byte block. It simply continues through the next block. The field is logically terminated by two End-of-file marks in the field. The reminder of the block is unused.
Code
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] privatestruct DBTHeader { publicInt32 nextBlockID; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public byte[] reserved1; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)] public string fileName; public byte version; // 0x03 = Version III, 0x00 = Version IV [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] reserved3; publicInt16 blockLength; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 490)] public byte[] reserved4; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)] privatestruct MemoHeader { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public byte[] reserved; publicInt16 startPosition; publicInt32 fieldLength; }
void Main() { int[] blocks = {347,750,1095,1439,1781}; List<myData> d = new List<myData>(); using (FileStream fs = File.OpenRead(@"c:\temp\myEmp.fpt")) { d = blocks.Select ((b,i) => new myData { RecNo = i, Content=GetMemo(fs,b)}).ToList(); } } publicstring GetMemo(FileStream stream, int blockNumber) { byte[] blockSize = newbyte[4]; stream.Seek(blockNumber * 64, SeekOrigin.Begin); stream.Seek(4, SeekOrigin.Current); // advance type stream.Read(blockSize, 0, 4); int memoSize = BitConverter.ToInt32( blockSize.Reverse().ToArray(), 0 ); byte[] bytes = newbyte[memoSize]; stream.Read(bytes, 0, memoSize); return Encoding.ASCII.GetString(bytes); } public class myData { public int RecNo { get; set; } public string Content { get; set; } }
You may also view the DBT/FPT file in hexadecimal format in VFP:
DO HOME()+'\tools\hexedit\hexedit.app' WITH 'YourFile.FPT'