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

Question

Question

download search results

SDK
asked on November 28, 2017

I'm trying to write an application that runs a search in Laserfiche and downloads the results.  These could be images, electronic docs, or folders.  So the functionality i'm mostly looking for is to export the docs as normal, but if the search hit is a folder, i want to preserve the folder structure and documents under it just like right clicking - > download folder contents.  Doing this from the client will export the folder and give me the documents and text for all docs under that folder.  But when i try and do this programmatically using CAT, it's exporting the folder and the contents, but only images, not the electronic files.  scrolling through the ExportOptions there isn't much to work with and the DocumentPart property doesn't seem to help either, and i'm wondering if i'm going about this the right way or if this is just a shortcoming of the CAT Export function?  Below is a snippet of what i'm doing, any guidance would be appreciated.

 

            Dim con As Object = conn.GetConnectionString
            Dim sess As Session = Session.CreateFromSerializedLFConnectionString(con)


            Dim so As New SearchOptions
            so.Query = boxsyntax.Text
            so.OpenIfOneResult = False
            so.NewWindow = False
            so.EagerlyRetrieveResults = True


            Dim hits As List(Of Integer) = conn.LaunchSearch(so)
            Dim eo As New ExportOptions
            eo.DestinationPath = "C:\testexport"
            eo.DoNotPrompt = True
            eo.ConflictOption = ExportConflictOption.Rename


            mainwindow.ExportById(hits, eo)

0 0

Replies

replied on November 28, 2017

This is a limitation of the ExportByID method (it exports edocs or images but not both), but you can relatively easily export the folder structure yourself since you have the Session object and the list of IDs:

Imports Laserfiche.RepositoryAccess
Imports Laserfiche.DocumentServices

' ....

    For Each entryId As Integer In hits
        ExportEntry(raSession, entryId, "c:\\testexport")
    Next


    Sub ExportEntry(ByRef raSession As Session, ByVal entryId As Integer, ByVal basePath As String)

        Directory.CreateDirectory(basePath)

        Dim entry As EntryInfo = Laserfiche.RepositoryAccess.Entry.GetEntryInfo(entryId, raSession)

        If entry.EntryType = EntryType.Shortcut Then
            Dim shortcut As ShortcutInfo = entry
            entry = Laserfiche.RepositoryAccess.Entry.GetEntryInfo(shortcut.TargetId, raSession)
        End If

        If entry.EntryType = EntryType.Document Then
            Dim Doc As DocumentInfo = entry
            Dim docExp As DocumentExporter = New DocumentExporter()

            ' Export the edoc if it exists
            If Doc.IsElectronicDocument Then
                docExp.ExportElecDoc(Doc, Path.Combine(basePath, Doc.Name) & "." & Doc.Extension) ' TODO: make sure the file name is valid
            End If

            ' Export the pages if they exist
            If Doc.PageCount > 0 Then
                docExp.PageFormat = DocumentPageFormat.Tiff
                docExp.ExportPages(Doc, Doc.AllPages, Path.Combine(basePath, Doc.Name) & ".tif")
            End If
        Else
            ' Export subfolders
            Dim folder As FolderInfo = entry
            Directory.CreateDirectory(Path.Combine(basePath, folder.Name)) ' TODO: make sure the folder name is valid

            Dim elSettings As New EntryListingSettings()
            elSettings.AddColumn(SystemColumn.Id)

            Dim folderContents As New List(Of Integer)

            Using entryListing = folder.OpenFolderListing(elSettings)
                For rownum = 1 To entryListing.RowCount
                    Dim subEntryId As Integer = entryListing.GetDatum(rownum, SystemColumn.Id)
                    folderContents.Add(subEntryId)
                Next
            End Using

            For Each subEntryId As Integer In folderContents
                ExportEntry(raSession, subEntryId, Path.Combine(basePath, folder.Name)) ' TODO: make sure the folder name is valid
            Next
        End If
    End Sub

 

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

Sign in to reply to this post.