C# samples

C# samples demonstrate a way to use the TextConverter component from multiple .NET languages. You can automate TextConverter from:

- any .NET application

- as a server component for your web application and automate it from an ASP.NET page.

Microsoft Visual Studio.NET

Create or open a C# project. Add the <sample>.cs file into the project or just copy its contents into one of the existing files in the project. Once this is done, there is one final step for the compilation to be successful: add a reference to the appropriate .NET assembly (ConverterX). This can be done in the following ways:

1. Switch to the solution explorer tab, expand the project node, right click on the References node and select "Add Reference". Follow the directions below.

2. Select the project node and from the project menu select "Add Reference". Follow the directions below.

Click the "Browse" button in the "Add Reference" dialog, locate SimX.ConverterX.Interop.dll in the installation folder, click "OK", and now you can compile.


Command Line:

csc /t:exe /r:<TargetInstDIR>\SimX.ConverterX.Interop.dll  <sample>.cs

For a console application the /t:exe is not necessary. This will produce <sample>.exe file in the same folder as <sample>.cs.

This sample creates an instance of the TextConverter object, loads a project file and runs the conversion.

using System;
using System.Reflection;
using SimX.ConverterX.Interop;

class TextConverterStep1
{
 static void Main( string[] args )
 {
  try
  {
   ConverterXClass cnv = new ConverterXClass();
   String path = cnv.GetStartPath();
   path += @"Samples/TextConverter/Manual Mode/1 Well formed input/1.1 Products.ConverterX";
   cnv.OpenProject( path );
   int n_recs = cnv.Convert( "" );
   Console.WriteLine( "{0} records were converted successfully.", n_recs );
  }
  catch( Exception e )
  {
   Console.WriteLine( "Error: {0}", e.Message );
  }
  int i = 0;
  while( i != 13 ) i = Console.Read();
 }
}

The next sample creates an instance of the TextConverter object, sets the output database table, sets several conversion options, loads an input text file and runs the conversion.

using System;
using System.Reflection;
using SimX.ConverterX.Interop;

class TextConverterStep2
{
 static void Main( string[] args )
 {
  try
  {
   ConverterXClass cnv = new ConverterXClass();
   String path = cnv.GetStartPath();
   path += @"Samples/TextConverter/Manual Mode/1 Well formed input/";
   ITDataSource ds = cnv.GetOutputDS();
   ds.SetDS( path + "Products.dbf" );
   cnv.field_delimiter   = ",";
   cnv.record_delimiter  = "<LF>";
   cnv.firstrow_colnames = true;
   cnv.skip              = 1;
   cnv.LoadTextFile( path + "1.1 products.txt", true );
   int n_recs = cnv.Convert( "" );
   Console.WriteLine( "{0} records were converted successfully to the output database table:\n{1}", n_recs, path + "Products.dbf" );
  }
  catch( Exception e )
  {
   Console.WriteLine( "Error: {0}", e.Message );
  }
  int i = 0;
  while( i != 13 ) i = Console.Read();
 }
}