Please enable JavaScript to view this site.

Altova MapForce Server 2020 Advanced Edition

The following example illustrates how to run a mapping execution file (.mfx) from C# code. On Windows, the example files are available at the following path: C:\Program Files\Altova\MapForceServer2020\etc\Examples.


The example solution is in the "Program Files" directory, which requires administrative rights. Either run Visual Studio as administrator, or copy the solution to a different folder where you don't need administrative rights.



MapForce Server is installed and licensed

If you are creating a new Visual Studio project, add a reference to the MapForce Server assembly (see .NET Interface). You can skip this step if you are running the existing MapForce Server API example, because the example already references the MapForce Server assembly.

On the Build menu of Visual Studio, click Configuration Manager and set a correct build platform, for example Debug | x86  (or Debug | x64, if applicable). Do not use "Any CPU" as platform.

If you have installed MapForce Server 64-bit, then the application which calls the API (such as the sample one below) must also be built for the 64-bit platform in Visual Studio. Also, the path to the MapForce server executable must be adjusted accordingly in the code.


Running the .mfx file

The code below does the following:


It creates a new instance of Altova.MapForceServer.Server. This is the object you will subsequently be working with.

It sets a working directory where execution takes place. Input files are expected to exist in this directory if you referred to them using a relative path. Output files will also be created in this directory. Namely, the server execution file run by this example (TokenizeString.mfx) reads data from a file called AltovaTools.xml, which is accompanied by the AltovaTools.xsd schema. These files must exist in the working directory in order for the .mfx file to run successfully.

It runs the TokenizeString.mfx file. The path to this file is supplied as argument to the Run method. Upon successful execution, a .csv file representing the mapping output will be created in the working directory.


namespace MapForceServerAPI_sample


  class Program


      static void Main(string[] args)


          //Create a MapForce Server object

           Altova.MapForceServer.Server objMFS = new Altova.MapForceServer.Server();


          //Set a working directory - used as a base for relative paths (you may need to adapt the path to the installation folder)

           objMFS.WorkingDirectory = "C:\\Program Files\\Altova\\MapForceServer2020\\etc\\Examples";


          //Default path to the MapForce Server executable is the installation path (same dir with the MapForceServer.dll)

          //In case you moved the binaries on the disk, you need to explicitly set the path to the .exe file

          //objMFS.ServerPath = "C:\\Program Files (x86)\\Altova\\MapForceServer2020\\bin\\MapForceServer.exe";


          //Set global resource file and configuration, if your mapping uses global resources

          //objMFS.SetOption( "globalresourcefile", "GlobalResource.xml" ); // "gr" can be used as short name for "globalresourcefile"

          //objMFS.SetOption( "globalresourceconfig", "Default" ); // "gc" can be used as short name for "globalresourceconfig"


          //Prepare the parameters, if your mapping uses parameters

          //objMFS.AddParameter( "testparam1", "value 1" );


          //Run the mapping; input and output paths are stored inside the MFX file

          // NOTE Please adapt the path to the input file in order to run the sample

          if (objMFS.Run("C:\\Program Files\\Altova\\MapForceServer2020\\etc\\Examples\\TokenizeString.mfx"))

               System.Console.WriteLine("Success - finished execution");






© 2019 Altova GmbH