Open DBF directly from C# using XSharp Assemblies

This forum is meant for examples of X# code.

Post Reply
charl.esterhuizen
Posts: 2
Joined: Mon Jul 14, 2025 6:13 am
Location: South Africa

Open DBF directly from C# using XSharp Assemblies

Post by charl.esterhuizen »

Hi all
I need to open DBF files in a C# project. I don't want to use Microsoft.Jet.OLEDB because if the dependency of it be installed and also it lacks a lot of functionality. The same goes for all the other "DBF Readers" I could find.

My problem is I am not allowed to use any other language except C# so a XSharp project is out of the question.

My question is, is it possible to reference the XSharp assemblies directly from C#? If so, can someone point me to a Example perhaps?

Regards
Charl
User avatar
robert
Posts: 5107
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Open DBF directly from C# using XSharp Assemblies

Post by robert »

Charl,

Yes, that is possible. Unfortunately, we do not have an example for this.
But this is the short description of what you need to do.

To open DBFs you need to include XSharp.Core, XSharp.RT, XSharp.RDD and XSharp.Macrocompiler.
The easiest way to open the DBFs is to use the completely strongly static methods in the CoreDb class.
This class is in the XSharp namespace.
You will find methods for each of the normal DBF related operations: UseArea(), Skip(), FieldGet(), FieldPut() etc.
Properties like EoF, BoF etc are also represented as methods.
The Macrocompiler is needed when you use indexes, filters etc.

If you want to set "global state", such as SetDeleted(), SetSoft() etc., then there are methods in the Functions class. You can also access the properties in the XSharp.Runtimestate.
Please use the X# help file for documentation about CoreDb and RuntimeState.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 4109
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Open DBF directly from C# using XSharp Assemblies

Post by wriedmann »

Hi Charl,
I have done something similar in a X# Core dialect class - and the Core Dialect is the dialect that cannot use any xbase specific datatypes or functionalities. In theory you could translate my code to C#, or I could try to build an assembly, and you can use ILSpy to translate it to C#.
Wolfgang
CoreDBF.zip
(2.95 KiB) Downloaded 1378 times
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
wriedmann
Posts: 4109
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Open DBF directly from C# using XSharp Assemblies

Post by wriedmann »

Hi Charl,
I have now tried to compile this class to a single assembly, but I had to remove references to the XBase date datatype.
You can find the binary here:
CoreDBF_Binary.zip
(11.83 KiB) Downloaded 1320 times
Wolfgang
P.S. even if XSharp can be used free of charge, please consider paying something to the development team if this software works for you. Writing the RDD and making it stable was a lot of work for them.
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
charl.esterhuizen
Posts: 2
Joined: Mon Jul 14, 2025 6:13 am
Location: South Africa

Re: Open DBF directly from C# using XSharp Assemblies

Post by charl.esterhuizen »

Thanks all for responding. I will look into the suggestions as soon as I have time
Post Reply