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

Question

Question

All documents corrupt when one fails during a session

SDK
asked on August 13

The title might be worded funky, but I'm not sure how else to summarize. Let me explain what I'm trying to do. I have a SDK script that loops through files inside of a regular Windows folder. Then, in Laserfiche, it creates a document for each file and finally imports the file into the document. If anything goes sideways during this process, all files are corrupt and the process has to be restarted. Is there a way to commit each file/document before the session is properly closed? Below is a small snippet. I removed the try catch and such ...

DocumentImporter import = new DocumentImporter();
string lfFolderPath = @"somepath";
FolderInfo fi = Folder.GetFolderInfo(lfFolderPath, session);

for (int i = 0; i < fileCollection.Count; i++)
{
    string docName = fileCollection[i].Name;
    string path = fileCollection[i].Path;
    DocumentInfo docInfo = new DocumentInfo(session);
    docInfo.Create(fi, docName, volumeName, EntryNameOption.Overwrite);
    docInfo.Save();
    import.Document = docInfo;
    import.OcrImages = false;
    import.ImportImages(path);
}

It works quite nicely, unless something goes awry, such as a file is deleted from the Win folder mid-process. I'd just like to keep the LF documents that were already created in a previous loop without corruption. Any ideas? Thanks for your time :)

0 0

Answer

SELECTED ANSWER
replied on August 14

I don't know that this would help, but after you finish the import of each document, you should dispose of the docInfo object.  So Line 15 should be 

docInfo.Dispose();

 

0 0
replied on August 14

Thank you, I'll try that.

0 0
replied on August 15

That was it. Thanks again!

0 0

Replies

replied on August 13

What is corrupted about the other documents? ImportImages is a synchronous operation, so it should complete before moving on to the next entry in the loop.

0 0
replied on August 14 Show version history

Initially the document has the proper icon (such as for audio or video) with a lock icon. If all uploads complete without error, the locks disappear. If one or more fail, all the files in the session get the following icon and can't be opened.

 

0 0
replied on August 14

Bert's suggestion should fix this. Your documents aren't corrupt, they just weren't unlocked after being imported. An easy way to fix this is to wrap the DocumentInfo creation in a using block to automatically dispose of each one when it goes out of scope. For example:

using (DocumentInfo docInfo = new DocumentInfo(session))
{
    // Import code goes here
}

 

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

Sign in to reply to this post.