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

Question

Question

Read document from repository in C#

SDK
asked on November 13, 2014

I am able to connect to repository and search for the document using RA in SDK in a C# application. How do I now read the contents of that document in a filestream please? Below is the code:

 

  // Using the overloaded RepositoryRegistration constructor
            RepositoryRegistration myRepoReg = new RepositoryRegistration("Laserfiche server", "repository name");
            Session mySess = new Session();
            mySess.IsSecure = true;
            mySess.LogIn("username", "pasword", myRepoReg);

            Search LFSearch = new Search(mySess);
            LFSearch.Command = "tax";
            LFSearch.Run();

            // The SearchStatistics class 
            SearchStatistics SS = LFSearch.GetSummaryStats();
            Console.WriteLine("Entries Found: " + SS.DocumentCount);

            SearchListingSettings Settings = new SearchListingSettings();
            SearchResultListing Results = LFSearch.GetResultListing(Settings);

 

Thanks,

Priya

1 0

Answer

SELECTED ANSWER
replied on November 17, 2014

To export the edoc unchanged, use


string mimeType = "";
using (FileStream fileStream = File.Create(m_filePath))
using (LaserficheReadStream edocStream = document.ReadEdoc(out mimeType))
{
    edocStream.CopyTo(fileStream);
}

 

2 0

Replies

replied on November 13, 2014

You can use the DocumentServices.DocumentExporter class to easily export document contents. Here is some sample code for exporting the images for all documents in the search results:

 

for (int i = 1; i <= Results.RowCount; i++)
{
    int docid = (int)Results.GetDatum(i, SystemColumn.Id);
    EntryType eType = (EntryType)Results.GetDatum(i, SystemColumn.EntryType);

    if (eType == EntryType.Document)
    {
        DocumentInfo document = Document.GetDocumentInfo(docid, repo.Session);
        if (document.PageCount > 0)
        {
            using (PageInfoReader pageInfos = document.GetPageInfos())
            {
                foreach (PageInfo pageInfo in pageInfos)
                {
                    if (pageInfo.ImageDataSize > 0)
                    {
                        DocumentServices.DocumentExporter docExporter = new DocumentServices.DocumentExporter();
                        docExporter.PageFormat = DocumentServices.DocumentPageFormat.Png;

                        string imageFilePath = "c:\\temp\\" + document.Id.ToString() + "_" + pageInfo.PageNumber + ".png";
                        // to export directly to a file:
                        //docExporter.ExportPage(document, pageInfo.PageNumber, imageFilePath);

                        using (System.IO.FileStream fileStream = System.IO.File.Create(imageFilePath))
                        {
                            docExporter.ExportPage(document, pageInfo.PageNumber, fileStream);
                        }
                    }
                }
            }
        }
    }
}

 

1 0
replied on November 13, 2014

Thanks. I will try. Will it export all into the filestream object please? 

 

Priya

 

0 0
replied on November 13, 2014

Yes, it exports the image into the file stream.

0 0
replied on November 14, 2014

Thanks. When I export using DocumentExporter, is it possible to export as pdf instead of png please? My original file is pdf and I do not see PDF in DocumentPageFormat. Please help.

0 0
replied on November 14, 2014

If you want to export your electronic document unchanged then you shouldn't use DocumentExporter or PdfExporter.  The post I linked in your last question had sample code for this.

0 0
replied on November 14, 2014

Can you please send me the link again?

 

Thanks,

Priya

0 0
replied on November 17, 2014

Can you please post the link where I can export my electronic document unchanged to a file stream object in C#  application?

0 0
SELECTED ANSWER
replied on November 17, 2014

To export the edoc unchanged, use


string mimeType = "";
using (FileStream fileStream = File.Create(m_filePath))
using (LaserficheReadStream edocStream = document.ReadEdoc(out mimeType))
{
    edocStream.CopyTo(fileStream);
}

 

2 0
replied on November 17, 2014

If I give m_filePath as C:\\temp\\test1.pdf, it says that "the process cannot access file as it is being used by another process".  What should be the value for that please?

0 0
replied on November 17, 2014

Thanks very much, I got it working.

 

Thanks,

Priya

0 0
replied on November 17, 2014

Which line is throwing that exception? could it be open in another process?

0 0
replied on November 17, 2014

I got it fixed, thanks.

 

Priya

0 0
replied on November 13, 2014

Can someone please help me with this?

 

Thanks

Priya

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

Sign in to reply to this post.