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

Question

Question

sdk all repositories

SDK
asked on February 10, 2016

Currently i am trying to learn sdk and make a simple application but most of the sample codes had server name and repository hard coded. What i am trying to achieve is similar to what laserfiche client does. It shows you list of available repositories that user could choose from. Is there a way to achieve that. 

thanks

 

0 0

Answer

SELECTED ANSWER
replied on February 10, 2016

If you are using the RepositoryAccess .NET library, you can scan for all repositories with the following code:

try
{
    ServerCollection allServers = Server.GetAllServers(new TimeSpan(0, 0, 20)); // The timespan means wait up to 20 seconds

    List<RepositoryRegistration> allRepositories = new List<RepositoryRegistration>();

    foreach (Server server in allServers)
    {
        try
        {
            allRepositories.AddRange(server.GetRepositories());
        }
        catch (Exception ex)
        {
            // Log error here
        }
    }
}
catch (Exception ex)
{
    // Log error here
}

Now the allRepositories list contains the available repositories.

2 0
replied on February 16, 2016

Thanks. that's exactly what i was looking for. One more question. How can i browse through contents of a folder. Let's say i have a name of the folder in the repository and i want to retrieve all of its files and folders how could this be done.

Thanks in advance.

0 0
replied on February 16, 2016

Use FolderInfo.GetFolderListing to get the contents of a folder. Here is sample code that gets the contents of a folder and exports all documents:

string folderpath = @"\my\folderpath";
FolderInfo folder = Folder.GetFolderInfo(folderpath, session);

EntryListingSettings settings = new EntryListingSettings();
settings.AddColumn(SystemColumn.Name);
settings.AddColumn(SystemColumn.Id);
settings.AddColumn(SystemColumn.EntryType);
settings.SetSortColumn(SystemColumn.Name, SortDirection.Ascending);

using (FolderListing listing = folder.OpenFolderListing(settings))
{
    foreach (var row in listing)
    {
        EntryType etype = (EntryType)row[SystemColumn.EntryType];
        int entryId = (int)row[SystemColumn.Id];
        string entryName = (string)row[SystemColumn.Name];

        // Export documents
        if (etype == EntryType.Document)
        {
            DocumentExporter exporter = new DocumentExporter();

            DocumentInfo document = Document.GetDocumentInfo(entryId, session);
            if (document.IsElectronicDocument)
            {
                string exportPath = @"c:\export\" + entryName + "." + document.Extension;
                exporter.ExportElecDoc(document, exportPath);
            }
            else if (document.PageCount > 0)
            {
                string exportPath = @"c:\export\" + entryName + ".tif";
                exporter.PageFormat = DocumentPageFormat.Tiff;
                exporter.ExportPages(document, document.AllPages, exportPath);
            }
        }
    }
}

 

0 0
replied on February 16, 2016

Awesome. What about folders inside folders. Do i need some sort of recursion?

0 0
replied on February 16, 2016

Yes, but make sure you close the FolderListing of folder A before recursing and retrieving the FolderListing for folder B. There is a limit to how many listings your session can have open at once.

0 0
replied on February 16, 2016

Are there any examples that could help me? Samples only contains folder browser but nothing about folder inside another folder. Sorry, recursion is my weakness in programming. 

0 0
replied on February 16, 2016 Show version history

Here is a method that crawls a folder recursively:

static void CrawlFolder(Session session, int folderId, int depth = 0)
{
    FolderInfo folder = Folder.GetFolderInfo(folderId, session);

    Console.WriteLine(folder.Path);

    EntryListingSettings settings = new EntryListingSettings();
    settings.AddColumn(SystemColumn.Name);
    settings.AddColumn(SystemColumn.Id);
    settings.AddColumn(SystemColumn.EntryType);
    settings.SetSortColumn(SystemColumn.Name, SortDirection.Ascending);

    List<int> subfolders = new List<int>();

    using (FolderListing listing = folder.OpenFolderListing(settings))
    {
        foreach (var row in listing)
        {
            EntryType etype = (EntryType)row[SystemColumn.EntryType];
            int entryId = (int)row[SystemColumn.Id];

            if (etype == EntryType.Document)
            {
                DocumentInfo doc = Document.GetDocumentInfo(entryId, session);
                Console.WriteLine("  " + doc.Name);
            }
            else if (etype == EntryType.Folder || etype == EntryType.RecordSeries)
            {
                FolderInfo subfolder = Folder.GetFolderInfo(entryId, session);

                subfolders.Add(entryId);
            }
        }
    }

    // Now that the FolderListing is closed, crawl the subfolders
    foreach (int subfolderId in subfolders)
    {
        CrawlFolder(session, subfolderId, depth + 1);
    }
}

Call the method with the Id of the folder to crawl.

4 0
replied on February 16, 2016

Thanks a lot Robert.

0 0

Replies

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

Sign in to reply to this post.