Search code examples
c#encodingcharacter-encodingdbfcodepages

Encoding DBF file into 852 codepage doesn't work


I'm having a problem with changing the codepage of a DBF file from 437 to 852.

I inspected the code that Encodes the datatable and it seems that inside the Visual Studio it correctly encodes to 852 but after moving the encoded file and replacing it with the original it comes back as if encoding didn't happen? So I'm thinkinh that the code for encoding works fine, but something else is changing the file back to 437 codepage! Please help...

Sample Code:

DbfRecord orec = new DbfRecord(odbf.Header);
orec.AllowDecimalTruncate = true;
orec.AllowIntegerTruncate = true;

foreach (DataRow DR in EndodedDataTable.Rows)
{
    for (int i = 0; i < EndodedDataTable.Columns.Count; i++)
    {
        orec[i] = DR[i].ToString();
    }
    odbf.Write(orec, true);
}

odbf.Close();

File.Delete(OriginalFileName);
File.Move(TempFileName, OriginalFileName);

Method that does the encoding:

http://pastebin.com/jPqJMxen


Solution

  • It turns out that my method for encoding from 437 to 852 works fine but the additional code that created temporary file and moved it to original file caused a lot of confusion in the code and therefore didn't work correctly...

    I ended up directly using the encoded datatable to write it into access file since that was my original intention

    Method that returns datatable with codepage 852 encoding:

    http://pastebin.com/jPqJMxen

    ~ ChenChi