C# Samples


There is a way to use the TextConverter component from multiple .NET languages. You can automate TextConverter from any .NET application, both desktop and server (for an instance, in your web ASP.NET application page). Here are samples in C#

In Microsoft Visual Studio.NET

Create or open a C# project. Add a reference to the appropriate .NET assembly (TextConverterLib). To do that:

  1. Open the solution explorer, expand the project node, right click on the References node and select "Add Reference".
  2. Click the "Browse" button, locate TextConverterLib.dll in the installation folder, click "OK".

Command Line:

Use the /reference: option (Short form: /r) of the Visual C# Compiler:

csc /t:exe /r:<TargetInstDIR>\TextConverterLib.dll  <sample>.cs

Code Example

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

using System;
using System.Reflection;
using CONVERTERLib;

class TextConverterSample
{
    public const string TC_PROJECT_FOLDER = "C:\\Projects\\";
    public const string CONVERTER_FILE = "TextConverterProject.ConverterX";
    public const string INPUT_FILE = "in.txt";
    public const string OUTPUT_FILE = "out.csv";

    static void Main( string[] args )
    {
        try {
            ConverterX cnv = new ConverterX();
            cnv.OpenProject( TC_PROJECT_FOLDER + CONVERTER_FILE );
            cnv.SetInputFile( TC_PROJECT_FOLDER + INPUT_FILE );
            ITDataSource src = cnv.GetOutputDS();
            src.SetDS( TC_PROJECT_FOLDER + OUTPUT_FILE );
            src.csv_include_column_names = true;
            src.csv_col_separator = "|";
            if( !cnv.IsValid() )
                Console.WriteLine( "Converter is not valid! Please check the project file: " + CONVERTER_FILE );
            cnv.SetBatch( false );
            int retValue = cnv.Convert( "" );
            Console.WriteLine( "Converted: " + retValue );
        } catch( Exception e ) {
            Console.WriteLine( "Error: {0}", e.Message );
        }
    }
}



Back (API)