Sunday, September 8, 2013

OnBase Unity Script to Export an Image

Link to other Onbase Scripts

Writing a script in VB or C# for OnBase is not hard once you take API course or you get you hands on the SDK for OnBase. I had neither the first time I wrote a VBScript to export a file from OnBase. I read through some samples and fumbled my way through only to realize that the script I wrote could only export the first page of an image which multiple pages appended to it. So here's a basic Unity script written in C# which will export the whole file from a workflow action to a local drive. Enjoy!

namespace SaveToFile
{
    using System;
    using System.Text;
    using Hyland.Unity;
    using Hyland.Unity.Workflow;
    
    
    ///





    /// Save a file to disk
    ///
    public class SaveToFile : Hyland.Unity.IWorkflowScript
    {
        
        #region IWorkflowScript
        ///





        /// Implementation of .
        ///
        ///
        ///
        ///
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            // Add Code Here
try{
string dirPath = @"c:\Temp\" + args.Document.ID + ".";

//create doc
Document wfdoc = args.Document;


//Redition
Rendition wfrend = wfdoc.DefaultRenditionOfLatestRevision;

//PageData
//using for the disposal
//PDF for the format

using (PageData wfPageData = app.Core.Retrieval.PDF.GetDocument(wfrend))
{
//Utility to write data page stream
Utility.WriteStreamToFile(wfPageData.Stream, dirPath + wfPageData.Extension);
}
}
catch(UnityAPIException Uex)
{
app.Diagnostics.Write(Uex.Message);
}
catch(Exception ex)
{
app.Diagnostics.Write(ex.Message);
}

        }
        #endregion
    }
}

No comments: