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

Question

Question

Documents exported to windows folder are empty

asked on March 15, 2024

I'm using a SDK script to export documents to a windows folder.  The script successfully moves the documents to the correct location, but they are empty 0KB files.  These are image files, so all of them are TIF/TIFF files, some have multiple pages, but I've tried both multiple page and single page documents with the same outcome.  I've also tried using the ExportPdf method with the same outcome.  I've also tried giving the Windows Folder full permissions for the user and that didn't make a difference.  When I copy the files into the locations in Laserfiche in the process right before the SDK Script, it moves the documents into the folders just fine and the image(s) are there.  Below is my script, and my current workflow.

protected override void Execute()

{
    // Get Path to Windows Folder for Exports
    String exportFolder = (String)GetTokenValue("DestinationPath");
    DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
    DocumentExporter docExporter = new DocumentExporter();
    String exportPath = System.IO.Path.Combine(exportFolder, doc.Name + ".tif");
    docExporter.PageFormat = DocumentPageFormat.Tiff;
    //   this parameter will be changed to find the number of pages
    int pageNumber = 1;
    using (FileStream fs = File.OpenWrite(exportPath))
    docExporter.ExportPage(doc, pageNumber, fs);
}

0 0

Answer

SELECTED ANSWER
replied on March 20, 2024

You should be able to install the latest updates for LF 11 to add the appropriate matching v11 references for the DocumentServices handling. That may resolve the issue.

 

In the interim changing your RepositoryAccess reference to the similar 10.4 handler should resolve the issue as that may work as well. 

 

:-)

1 0

Replies

replied on March 15, 2024 Show version history

It's been a while since I've done something like this so I'm a little rusty, but I don't think you need the file stream.

The following uses the default parameters which are just the DocumentInfo object, a Page Number, and a string file path.

docExporter.ExportPage(doc, pageNumber, exportPath);

Try that first; there are some other things to watch out for with streams, but for what you're doing I'm pretty sure you can do it without getting file/memory streams involved.

2 0
replied on March 18, 2024

Thanks for replying, Jason.  I did try it both with and without the File Stream component, both of them worked the same, it moved the files just fine, but there was no data in the files.

0 0
replied on March 18, 2024

That is odd, the only time I ever encountered 0kb export files was when I was using a stream and had to use Seek because to make sure it was at the start of the stream when it did the export.

0 0
replied on March 18, 2024

This is a dumb question, but does running the SDK script require some sort of license? We are on professional subscription license with xx full users.  I went as far as creating a share and giving Everyone full access, still 0 KB files are created. We know these two Laserfiche records have pages, one has 2 and the other one has 1 page. We do a warning about libraries mismatch.. not an error but warning.

0 0
replied on March 18, 2024 Show version history

It does not. Any script run by Workflow runs as the workflow service user, so much like Forms it doesn't require any licensing to interact with the repository.

That message you're seeing in the screenshot is likely because the RA version referenced in the code doesn't match the library reference.

This happens a lot when people copy/paste from examples that were created in older versions of Laserfiche.

The following screenshots are comparing one of my older scripts to a newly created script; the version number of the reference should correspond to the RAScriptClass the script inherits from (right-click the reference and select Details to see the version number).

 

 

0 0
replied on March 20, 2024

Thanks Jason, much appreciated.

0 0
replied on March 16, 2024

Amir,

There are two overloads on the DocumentExporter.ExportPage and DocumentExporter.ExportPages methods.  One accepts a Stream (filestream) as a parameter and one accepts a String (output path) as a parameter.  Your code example is using the filestream overload but you need to use the Create method on the filestream instead of the OpenWrite method.  Here is your modified code example that works on my machine;

        protected override void Execute()
        {
            // Get Path to Windows Folder for Exports
            String exportFolder = (String)GetTokenValue("DestinationPath");
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporter = new DocumentExporter();
            String exportPath = System.IO.Path.Combine(exportFolder, doc.Name + ".tif");
            docExporter.PageFormat = DocumentPageFormat.Tiff;
            //   this parameter will be changed to find the number of pages
            int pageNumber = 1;
            using (FileStream fs = File.Create(exportPath))
            docExporter.ExportPage(doc, pageNumber, fs);
        }

Here is the same code using the string output path overload and exporting all of the pages versus a single page;

        protected override void Execute()
        {
            // Get Path to Windows Folder for Exports
            String exportFolder = (String)GetTokenValue("DestinationPath");
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporter = new DocumentExporter();
            String exportPath = System.IO.Path.Combine(exportFolder, doc.Name + ".tif");
            docExporter.PageFormat = DocumentPageFormat.Tiff;
            docExporter.ExportPages(doc, doc.AllPages, exportPath);
        }

Depending on your use case my thought is that the output path overload is the cleaner piece of code.

1 0
replied on March 18, 2024

Thanks Cliff, I definitely prefer the doc.AllPages, makes it much cleaner than the solution I was using.  Unfortunately I'm still having the issue of empty files.  It feels to me that the Workflow is hanging on the SDK script, and doesn't fully complete, leaving the empty files.  Here is a screenshot of the Workflow after it is ran, that last step never changes from blue to green, like it is forever running.  Any ideas to be able to exit the loop successfully?  Thanks again for your help!

0 0
replied on March 18, 2024 Show version history

Amir,

To troubleshoot I would try to eliminate as many variables as possible.  First, I would do a simple workflow with only the SDK Script activity to export a document and run it against a single document to see if the issue is with your SDK code.  If that simple workflow runs without error then the issue has to be with the logic in the rest of the workflow.  If it fails then the issue is with your code.

The most common issue I have run into when exporting a document via workflow is to make sure that the account that the workflow service is running under has full permissions on the destination folder.

Also, I assume that the SDK Script activity in your workflow is bound to the current entry of the 'For Each Entry 2' activity and the documents in the For Each loop have valid Laserfiche pages?

2 0
replied on March 18, 2024

I agree with Cliff, your best bet is to start with the bare minimum and build up from there so you can eliminate variables.

The fact that the script activity is just staying active and never finishes makes it seem like it's not running correctly, which could indicate an issue with permissions in the target destination.

I've seen situations in which an account can write to a folder, but not change things that are already in the folder and that can break the export, however, that should have generated an error message rather than just stalling.

Something else worth noting; when you test the script from the editor it is running under your user account rather than the workflow service account, so if it works that way but not when you publish and run the workflow that would be helpful information.

0 0
replied on March 20, 2024

I'm providing update as I'm sure someone else will run into this problem. As Ramsey and Jason pointed out its a version issue. DocumentServices was 10.4 and RepositoryAccess 11.0. Even though it was a warning and not an error, if the version numbers are different it will probably not work correctly. 

Problem was that DocumentServices 11.0 doesn't exist selection or browsing in the default folder. After downgrading to 10.4 and everything starting to work we ended up looking at this post https://answers.laserfiche.com/questions/184977/Workflow-11-SDK-Script-unable-to-add-reference-to-DocumentServices and were able to browse to it and move everything up to 11. 

 

Here is the final version of the script using 110:

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

    /// <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 Path to Windows Folder for Exports
            String exportFolder = (String)GetTokenValue("DestinationPath");
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            DocumentExporter docExporter = new DocumentExporter();
//            String exportPath = System.IO.Path.Combine(exportFolder,GetTokenValue("ForEachEntry_CurrentEntry_ID") + "-" + GetTokenValue("ForEachEntry_CurrentEntry_Name") + "." + ".tif");
            String exportPath = System.IO.Path.Combine(exportFolder, doc.Name + ".tif");
            docExporter.PageFormat = DocumentPageFormat.Tiff;
            docExporter.ExportPages(doc, doc.AllPages, exportPath);
        }
    }
}

We are looking into sFTP transfer now so onto another problem. Thank you all for your assistance.

1 0
replied on March 17, 2024

Hi Amir,

I am looking to achieve something similar. A script to export documents to a Windows folder.

Would you mind sharing the tokens that you used in the "Assign Token Values"

Thanks in advance

Jonathan

0 0
replied on March 18, 2024

Hi Jonathan, I'm only using one token, it is the path to the Windows folder where I am exporting the files.  It just makes it easier instead of hard-coding in case I need to change the path.

Token Name: DestinationPath

Action: Create New Token

Token Value: C:\Test

0 0
replied on March 18, 2024

You could achieve the same outcome with ease using the Workflow Activity Bundle. There is a File Export to Windows activity included in the bundle, plus many other useful activities.

More info here:
https://marketplace.laserfiche.com/details/210806/Workflow-Activity-Bundle

 

Downloadable here:

https://licensing.nostello.com/Home/WcaInfo

 

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

Sign in to reply to this post.