This example uses the Visual Studio 2010 IDE. To begin, generate C# code from the DB_CompletePO sample mapping available in the <Documents>\Altova\MapForce2020\MapForceExamples\ directory, and then open the solution in Visual Studio.
By default, the name of the solution file is Mapping.sln, and it is located in the Mapping subdirectory relative to the directory where you saved the generated code. If you changed the application name from the mapping settings, then the name of the .sln file is changed accordingly. For example, if you changed the application name to MyApplication, then the solution file is called MyApplication.sln, and it is located in the MyApplication subdirectory.
Sample C# solution generated with MapForce
Open the MappingConsole.cs file, and locate the main(String args) method. The following code sample illustrates an extract from the main method. The mapping sources and targets are highlighted in yellow and are defined as parameters to the Run method. Since this mapping reads data from a database, there is also an input parameter which is a database connection string. If necessary, you can modify the connection string of the database.
Note that the file paths in the code below have been changed from absolute to relative.
Altova.IO.Input ShortPO2Source = Altova.IO.StreamInput.createInput("ShortPO.xml");
To define custom mapping source or target files:
•Locate the parameters passed to the Run method and edit them as required. In the sample above, the mapping input is a connection string to the CustomersAndArticles.mdb and ShortPO2Source . The mapping output is CompletePO2Target.
To add extra error handling code:
•Edit the code below the catch (Exception e) code
For instructions on how to change the data type of parameters supplied as mapping input/output, see Changing the data type of the mapping input/output (C#, Java).