Skip to main content
Version: Next

Expert Mode and C# Code

To meet the most complex import needs that cannot be handled solely by field mapping, ImportDocs allows you to inject custom C# code.

Accessing the generated code

At the last step of the Wizard (Step 8), check the Edit generated C# code checkbox.

The tool then displays the ExtendedImportClass class. This code is dynamically generated from the settings made in the previous steps.

Why use custom code?

Here are some typical customization examples:

  • Complex calculations: Calculate a due date or total amount from multiple source columns.
  • API/SQL calls: Query a third-party database or external API during import to enrich the data.
  • Advanced formatting: Transform a character string (e.g., convert to uppercase, extract part of the text).
  • Conditional validation: Decide to ignore a row based on very specific business criteria.

Key methods

The class to inherit exposes several methods that you can override:

OnBeforeImportRow

Called before processing a file row. Ideal for preparing variables or validating the row.

OnAfterImportRow

Called just after creating (or updating) the Avanteam document. Allows you to perform post-processing (e.g., send an email, move a linked file).

Quick example

Here's how to transform a name to uppercase before import:

public override void OnBeforeImportRow(ImportRowEventArgs e)
{
// We get the value from the "NOM" column (index 0 here)
string nom = e.SourceRow[0].ToString();

// We transform it and reinject it into the buffer
e.SourceRow[0] = nom.ToUpper();
}

Using NLog in your code

You can log your own messages in ImportDocs' standard flow:

Log.Info("Processing row {0} in progress...", e.RowIndex);
if (montant > 1000) {
Log.Warn("High amount detected for row {0}", e.RowIndex);
}
Expertise required

Editing C# code requires development skills. A syntax error will prevent the import from launching. Always test your code on a reduced data sample (Step 7: Filtering).