Skip to main content
Kofax

Publish a Batch Class Programmatically

3014511

Question / Problem: 

Is there a way to publish a Batch Class externally using the Kofax Capture API outside of Administration?

Answer / Solution: 

Yes there is. The API exists in the Kofax.Capture.AdminModule library and contains several things you can do outside of Administration such as Publishing, Importing, Exporting, etc. Below is a console application written in C# that demonstrates how this can be accomplished. In this application, you would execute the program while passing one or more Batch Class names to publish. There is also code to keep track and count any errors that may be encountered.

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kofax.Capture.AdminModule.InteropServices;
using Kofax.Collection;

namespace PublishBatchClass
{
    class Program
    {
        private static AdminLogin oAdminLogin = null;
        private static IAdminApplication oAdminApplication = null;
        
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("PublishBatchClass BatchClass1,BatchClass2,BatchClass3,...");
            }
            else
            {
                try
                {
                    Console.WriteLine("Logging into Kofax Capture...");
                    oAdminLogin = new AdminLogin();
                    oAdminLogin.Login("", "");
                    oAdminApplication = oAdminLogin.ActiveApplication;

                    string[] classes = args[0].Split(',');

                    foreach (BatchClass bc in oAdminApplication.BatchClasses)
                    {                        
                        if (classes.Contains(bc.Name))
                        {
                            Console.WriteLine("Publishing: " + bc.Name);
                            bc.Publish();
                            
                            if (bc.PublishErrors.Count > 0)
                            {
                                Console.WriteLine("  Errors:");
                                for (int ctr = 1; ctr <= bc.PublishErrors.Count; ctr++)
                                {
                                    Console.WriteLine("  " + bc.PublishErrors[ctr]);
                                }
                            }
                        }
                    }
                    Console.WriteLine("Process complete");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + "\n\n" + ex.StackTrace);
                }
                finally
                {
                    oAdminApplication = null;
                    if (oAdminLogin != null)
                        oAdminLogin.Logout();
                }
            }
        }         
    }
}

The complete project source code is attached below.

Applies to:  

Product Version
CAPTURE 10.0
  10.1
  10.2
  11.0

 

 

  • Was this article helpful?