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

Question

Question

Can metadata be exported out with a Laserfiche file?

asked on June 17, 2018

Hi All,

 

I have a query that I wanted some clarification on if possible, 

 

We would like to download all the files in a repository (over 400,000+) into a Network folder (native (electronic) files as they are) with their respective metadata. Is this possible? 

 

I have tried the following methods:

1. Download > Folder Contents - This allows me to save the actual file outside of Laserfiche which is great but it does not contain the metadata for each file? 

2. Briefcase > and renamed the file before saving to .gz.tar which when uncompressing, it brings the Volume files and not the actual file I want to export. 

Is there a way I can use the first method, but also have the metadata attached for each file associated to it? or, is there any other way this can be done? Making sure the files are the original files (electronic files and not the generated pages?)

 

With many thanks, 

Ziad

0 0

Answer

SELECTED ANSWER
replied on June 18, 2018 Show version history

Hi Ziad,

 

Try this code. Make reference to the DocumentServices and System.IO in the SDK script and update the file output path. I don't think you will need to alter anything else in there. The output should replicate the Laserfiche folder structure.

 

//get Document information for running entry
            DocumentInfo doc = (DocumentInfo)this.BoundEntryInfo;
            var template = doc.TemplateName;
            var metadata = doc.GetFieldValues();
            var entryId = doc.Id;
            var docName = doc.Name;
            var ext = doc.Extension;
            //get Parent folder Path for export
            var docPath = doc.GetParentFolder().Path;
            //create metadata document filename - append with _M
            var fileName = docName+"_M.txt";
            //create filepath - Update this to required output directory
            //the docPath will be the repository path
            //Make sure workflow user has rights to export to this directory
            var filePath = @"C:\TestFolder\docandmetadata\"+docPath+@"\";
            //If directory does not exist, create it
            if (!Directory.Exists(filePath))
                 Directory.CreateDirectory(filePath);
            //Export Electronic Document to path
            DocumentExporter docExporter = new DocumentExporter();
            docExporter.ExportElecDoc(doc, filePath+docName+"."+ext);
            //Create filestream for metadata export
            FileStream fs = new FileStream (filePath+fileName, FileMode.OpenOrCreate, FileAccess.Write);
            StreamWriter writer = new StreamWriter(fs);
           //output metadata fields
            foreach(var f in metadata)
                {
                 writer.Write(f.ToString());
                }
            //Dispose of writer and filestream object
            writer.Dispose();
            fs.Dispose();

 

2 0
replied on June 19, 2018

Hi Aaron,

 

Thank you so much for your assistance in this, 

Appreciate it a lot, 

 

Regards

Ziad

0 0

Replies

replied on June 18, 2018

You can generate a metadata report containing all of the field values. After exporting the electronc files, do Tasks->Generate Report->Metadata Report and select the field values to include. This will export one Excel/CSV/html file with the field values for the selected entries.

 

The other option is to use the SDK if you have programmer resources available. It's a relatively simple operation and I could give you sample code if that would help.

2 0
replied on June 18, 2018

Thanks Robert,

 

Would it be possible if you also share the code? I am in the middle of testing the report option within LF Client to see if that is exactly what we can use, 

 

Thank you again

Ziad

0 0
replied on June 19, 2018

To expand on Aaron's code:

static void ExportEdocsAndMetadata(Session session)
{
    try
    {
        string localFolderRoot = @"c:\Export";
        Directory.CreateDirectory(localFolderRoot);

        Queue<FolderInfo> foldersToExport = new Queue<FolderInfo>();
        foldersToExport.Enqueue(Folder.GetFolderInfo(1, session));
        List<int> processedEntries = new List<int>(); // avoid infinite loops if shortcuts are used (current code ignores them though)

        while (foldersToExport.Count > 0)
        {
            FolderInfo curFolder = foldersToExport.Dequeue();

            List<string> pathComponents = new List<string>() { localFolderRoot };
            pathComponents.AddRange(curFolder.Path.Split(new char[] { '\\' }).Select(pathComp => RemoveIllegalFileNameChar(pathComp)));
            string localFolderPath = Path.Combine(pathComponents.ToArray());
            Directory.CreateDirectory(localFolderPath);

            EntryListingSettings settings = new EntryListingSettings();
            using (FolderListing listing = curFolder.OpenFolderListing(settings))
            {
                foreach (var row in listing)
                {
                    int entryId = (int)row[SystemColumn.Id];

                    if (processedEntries.Contains(entryId))
                        continue; // duplicate

                    EntryInfo curEntry = Entry.GetEntryInfo(entryId, session);

                    if (curEntry.EntryType == EntryType.Document)
                    {
                        try
                        {
                            // Export the edoc
                            DocumentInfo curDoc = (DocumentInfo)curEntry;
                            if (curDoc.ElecDocumentSize > 0)
                            {
                                string contentType;

                                string edocPath = Path.Combine(localFolderPath, RemoveIllegalFileNameChar(curDoc.Name));
                                if (!edocPath.ToLower().EndsWith(curDoc.Extension.ToLower()))
                                    edocPath += "." + curDoc.Extension;

                                using (Stream fileStream = File.OpenWrite(edocPath))
                                using (Stream edocStream = curDoc.ReadEdoc(out contentType))
                                    edocStream.CopyTo(fileStream);
                            }

                            // Export the metadata
                            string metadataPath = Path.Combine(localFolderPath, RemoveIllegalFileNameChar(curDoc.Name));
                            if (!metadataPath.ToLower().EndsWith(curDoc.Extension.ToLower()))
                                metadataPath += "." + curDoc.Extension;

                            metadataPath += "_metadata.txt";

                            string metadataContents = String.Format("\"{0}\" field values:\n\n", curDoc.Path);

                            FieldValueCollection fvc = curDoc.GetFieldValues();
                            foreach (var field in fvc)
                            {
                                metadataContents += String.Format("{0}: {1}\n", field.Key, field.Value);
                            }

                            File.WriteAllText(metadataPath, metadataContents);
                        }
                        catch (Exception ex)
                        {
                            // Log the error and continue
                            Console.WriteLine(ex);
                        }
                    }
                    else if (curEntry.EntryType == EntryType.Folder || curEntry.EntryType == EntryType.RecordSeries)
                    {
                        // Add the folder to the TODO queue
                        foldersToExport.Enqueue((FolderInfo)curEntry);
                    }
                    else if (curEntry.EntryType == EntryType.Shortcut)
                    {
                        // ignore for now
                    }

                    processedEntries.Add(entryId);
                }
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

This will export all edocs and their corresponding metadata under c:\Export.

2 0
replied on June 19, 2018

Thank you so much for the detailed response there Robert, this will be very handy! really appreciate it.

 

Regards

Ziad

0 0
replied on August 15, 2019

Does anyone know if the metadata for documents in Laserfiche is stored on the file systems(volumes) with the content, or is it stored (and readable) in the supporting Laserfiche DBMS ?

1 0
replied on July 13, 2022

Hello, any question about the topic.  Poke me please!!!!

I have the same problem.

Regards

0 0
replied on July 20, 2022

Metadata is stored in the database.

0 0
replied on July 20, 2022

How can i  get acces a Database Laserfiche? 

Where i can to find info and examples about this.

 

Thank you for support

Gustavo Mayaute 

1 0
replied on July 20, 2022

We don't document the database schema, but if you are familiar with database designs it's not hard to see how the pieces fit together for metadata. The field values are in propval, with keys into propdef and toc ["property value", "property definition", "table of contents"].

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

Sign in to reply to this post.