C Sharp Workflow Agent Sample
18705
QAID # 18705 Published
Question / Problem:
I have installed Kofax Capture 10.1 and would like to get started developing a Workflow Agent in C# using the new Capture .NET libraries.
Are there any samples in C# available?
Answer / Solution:
Below is a sample Workflow Agent that processes after the Recognition Server module which simply writes out the Index Field values of all the Documents in the Batch to a text file.
First add references to the following Kofax Capture API DLLs:
Kofax.Capture.ACWFLib.dll Kofax.Capture.SDK.Workflow.dll Kofax.Capture.SDK.Data.dll
Following is the complete source code for the Workflow Agent.
Some notes regarding this project:
- Neither the
DbLite
norDbLiteOpt
libraries are required when using the new libraries for Workflow Agents. - The
ACDataElement
is replaced with theIACDataElement
. - The
WorkflowData
object is replaced with theIACWorkflowData
object. - Some COM-related aspects still exist and are required such as, in the project properties, Assembly Info,
COM
Visible
must be set toTrue
. Register for COM Interop does NOT need to be set. The same class attributes, (i.e.,Guid
,ClassInterface
,ProgId
), are still required.
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Threading.Tasks; using System.Runtime.InteropServices; using Kofax.Capture.ACWFLib; using Kofax.Capture.SDK.Workflow; using Kofax.Capture.SDK.Data; namespace WFAExportValues { [Guid("7F819B7B-7F21-4F5E-8699-51F09C93A088")] [ClassInterface(ClassInterfaceType.None)] [ProgId("WFAExportValues.ExportValues")] public class ExportValues : IACWorkflowAgent { public void ProcessWorkflow(ref IACWorkflowData oWorkflowData) { if (oWorkflowData.CurrentModule.ID.ToLower() == "fp.exe") { try { IACDataElement oRoot = oWorkflowData.ExtractRuntimeACDataElement(0); IACDataElement oBatch = oRoot.FindChildElementByName("Batch"); IACDataElement oDocument = oBatch.FindChildElementByName("Documents"); IACDataElementCollection oDocColl = oDocument.FindChildElementsByName("Document"); using (StreamWriter sw = new StreamWriter(@"C:\ProgramData\Kofax\CaptureSV\Logs\WFAIndexData.txt", true)) { foreach (IACDataElement oDoc in oDocColl) { IACDataElement oIndex = oDoc.FindChildElementByName("IndexFields"); IACDataElementCollection oIndexColl = oIndex.FindChildElementsByName("IndexField"); sw.WriteLine("Document: {0}", oDoc["UniqueID"].ToString()); foreach (IACDataElement oField in oIndexColl) { sw.WriteLine("Name: {0}, Value: {1}", oField["Name"].ToString(), oField["Value"].ToString()); } sw.WriteLine("----------------------------------------------------"); } } } catch (Exception ex) { using (StreamWriter sw = new StreamWriter(@"C:\ProgramData\Kofax\CaptureSV\Logs\WFAIndexData.txt", true)) { sw.WriteLine("************************************"); sw.WriteLine("Error: {0}", ex.Message); sw.WriteLine("************************************"); } } } } } }
Applies to:
Product | Version | Category |
---|---|---|
CAPTURE | 10.1 | Workflow Agent |