You are viewing limited content. For full access, please sign in.

Question

Question

Exporting Image from Repository Using Workflow Script Activity - But Using Different Credentials

asked on June 3, 2024

I've used scripts in Workflow before to export files and images from the repository to folders within our network, and this has worked very well. 

For an example of the script I'm referring to, this is one I use often that exports 1 page from a selected entry and saves it as a JPG on the server (via a File Path token from the Workflow): 

    public class Script1 : RAScriptClass110
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {

            // Get document
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;

            // Initialize Document Exporter
            DocumentExporter dExp = new DocumentExporter();

            // Export image from document
            var filePath = GetTokenValue("File Path").ToString();
            dExp.PageFormat = DocumentPageFormat.Jpeg;
            dExp.ExportPage(doc,1,filePath);

            // Cleanup document object
            doc.Dispose();

        }
    }

 

What I want to try to do now, that I'm not certain how to try to do, is I would like to push some of these image files into our public LFForms server, so that I can refer to them from public forms.  I have set-up a subfolder within the img folder on the public LFForms server, and ensured that I can access it from the internal server.  The problem I have is that since the public LFForms server is in the DMZ and not part of our domain, the same user credentials that are running Workflow do not work to access this shared folder on the DMZ server.  I need to be able to access this network path using a different username and password.  I don't mind having those credentials stored in the workflow.  I just have no idea how to change the script to allow it to do the export using different credentials.

Has anyone done anything like this and could provide some guidance on how it works, or point me to some resources about it?

Thank you!

0 0

Answer

SELECTED ANSWER
replied on June 4, 2024

Okay, I have something working.  It would have preferred to keep it all within the workflow, but this is working, so I'm calling to call it a win.

I created a BAT file and saved it on the machine that is running LFWorkflow.  I included the path to that BAT file as a token in Workflow.  Then I edited my script to call that BAT file after the image had been saved out of the repository. 

Ultimately, what this is doing is duplicating the contents of a folder within the LFForms img folder on the server within the domain, to the same folder location on the second server in the DMZ (which has been set-up as a file share so it can be accessed from the other server).  The final result is that the same folder on both servers contains the same files.

Here's the scripts I used. 

Here's the BAT file: 

net use \\DMZSERVER\SHAREDFOLDER PASSWORD /USER:USERNAME
robocopy "C:\Program Files\Laserfiche\Laserfiche Forms\Forms\img\SUBFOLDER" \\DMZSERVER\SHAREDFOLDER *.*

Replace \\DMZSERVER\SHAREDFOLDER twice with the actual path of the shared folder on the DMZ server.  Replace PASSWORD with the actual password.  Replace USERNAME with the actual username (I had to do \USERNAME because it isn't a domain user).  Replace SUBFOLDER with the actual subfolder in your server's files.

 

Then here is the C# script I am running from within Workflow.  It's taking in 3 things from the workflow: 1) the entry that is being exported, 2) the file path where the image is saved locally (that is the "C:\Program Files\Laserfiche\Laserfiche Forms\Forms\img\SUBFOLDER" path that was also references in the BAT file), and 3) the path to the BAT file. 

namespace WorkflowActivity.Scripting.ExportImagetoFilePath
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Diagnostics;
    using Laserfiche.RepositoryAccess;
    using Laserfiche.DocumentServices;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass110
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {

            // Get document
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;

            // Initialize Document Exporter
            DocumentExporter dExp = new DocumentExporter();

            // Export electronic document
            var filePath = GetTokenValue("File Path").ToString();

            dExp.PageFormat = DocumentPageFormat.Jpeg;
            dExp.ExportPage(doc,1,filePath);

            // Cleanup document object
            doc.Dispose();

            // Run the Batch file to move the images to the DMZ Server
            string batchFilePath = GetTokenValue("Batch File Path").ToString();
            Process.Start(batchFilePath);

        }
    }
}

 

1 0

Replies

replied on June 3, 2024

I don't believe there's any support for this in Workflow - all activities run as the service account.

I think it makes sense to split this operation into 2 steps - first export the image to a local temp file, and then copy it to the remote server. Is there a trust relationship between the DMZ domain and the local one? If so, then you can run as a DMZ account during the copy operation. It's possible to use LogonUser, but it means hard-coding credentials into the code, and it's a lot of code to add. Another approach would be to have a simple program to watch the output directory and copy files to the remote location. This program could run as a service and use the identity of the DMZ account. So no manual impersonation, but the tradeoff is the overhead of the Windows service interface.

1 0
replied on June 4, 2024

Okay - that makes sense.  I’ll play around with those options.

0 0
SELECTED ANSWER
replied on June 4, 2024

Okay, I have something working.  It would have preferred to keep it all within the workflow, but this is working, so I'm calling to call it a win.

I created a BAT file and saved it on the machine that is running LFWorkflow.  I included the path to that BAT file as a token in Workflow.  Then I edited my script to call that BAT file after the image had been saved out of the repository. 

Ultimately, what this is doing is duplicating the contents of a folder within the LFForms img folder on the server within the domain, to the same folder location on the second server in the DMZ (which has been set-up as a file share so it can be accessed from the other server).  The final result is that the same folder on both servers contains the same files.

Here's the scripts I used. 

Here's the BAT file: 

net use \\DMZSERVER\SHAREDFOLDER PASSWORD /USER:USERNAME
robocopy "C:\Program Files\Laserfiche\Laserfiche Forms\Forms\img\SUBFOLDER" \\DMZSERVER\SHAREDFOLDER *.*

Replace \\DMZSERVER\SHAREDFOLDER twice with the actual path of the shared folder on the DMZ server.  Replace PASSWORD with the actual password.  Replace USERNAME with the actual username (I had to do \USERNAME because it isn't a domain user).  Replace SUBFOLDER with the actual subfolder in your server's files.

 

Then here is the C# script I am running from within Workflow.  It's taking in 3 things from the workflow: 1) the entry that is being exported, 2) the file path where the image is saved locally (that is the "C:\Program Files\Laserfiche\Laserfiche Forms\Forms\img\SUBFOLDER" path that was also references in the BAT file), and 3) the path to the BAT file. 

namespace WorkflowActivity.Scripting.ExportImagetoFilePath
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using System.Diagnostics;
    using Laserfiche.RepositoryAccess;
    using Laserfiche.DocumentServices;

    /// <summary>
    /// Provides one or more methods that can be run when the workflow scripting activity is performed.
    /// </summary>
    public class Script1 : RAScriptClass110
    {
        /// <summary>
        /// This method is run when the activity is performed.
        /// </summary>
        protected override void Execute()
        {

            // Get document
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;

            // Initialize Document Exporter
            DocumentExporter dExp = new DocumentExporter();

            // Export electronic document
            var filePath = GetTokenValue("File Path").ToString();

            dExp.PageFormat = DocumentPageFormat.Jpeg;
            dExp.ExportPage(doc,1,filePath);

            // Cleanup document object
            doc.Dispose();

            // Run the Batch file to move the images to the DMZ Server
            string batchFilePath = GetTokenValue("Batch File Path").ToString();
            Process.Start(batchFilePath);

        }
    }
}

 

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.