Description

This C# program has been set-up for DMConnect Pro to export 3 data variables defined in the software to append to a . file.
In this application, DMConnect powered by Nuance has an OCR template to populate the meta-data fields, but the script will work for any named variable.

The script is applied in the Workflow designer ‘Scripts’ section once it’s complied.

Source Code

using System;
using System.IO;

namespace AppendToCSVfile
{
    //External script for DMConnect Zonal extraction to CSV file written by <esc>E 6/25/2020
    public class AppendCSV
    {
        public static void AppendToCSV(dynamic i, dynamic o)
        {
            //Bring in DMC fields
            String Column1Value = i.ItemNum;
            String Column2Value = i.Customer;
            String Column3Value = i.CreateDate;
            string path = @"c:\scan\DB-MAIN.csv";
            // Check if file exists, create if not
            if (!File.Exists(path))
            {
                // Create a file to write to, write column headers
                using (StreamWriter sw = File.CreateText(path))
                {
                    sw.Write("ItemNum,");
                    sw.Write("Customer,");
                    sw.WriteLine("CreateDate");
                }
            }

            // Append zonal extraction values to existing file as comma sep. values with newline after final value
            // 
            using (StreamWriter sw = File.AppendText(path))
            {
                sw.Write(Column1Value + ",");
                sw.Write(Column2Value + ",");
                sw.WriteLine(Column3Value);
            }
            o.OutputStatus = "Extraction Complete";

        }
    }
}

Screenshots

Screen shot shows the DMConnect script settings for this script