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

Question

Question

SDK Exception thrown when opening Electronic Document.

SDK
asked on December 5, 2016

Hi all,

I've tried to open a support case but they don't look at SDK exceptions unfortunately...

I'm having a bit of trouble opening an electronic document (.docx in this case) using the SDK. I'm using the below C# code to open the document.

private void displayDocument(int id)
        {
            OpenOptions oOptions = new OpenOptions();
            oOptions.MetadataVisibleTabs = MetadataTab.Fields;

            ClientManager lfclient = new ClientManager();
            using (lfclient)
            {
                MainWindow client;
                LaunchOptions options = new LaunchOptions();
                options.ServerName = "myServerName";
                options.RepositoryName = "myRepositoryName";
                options.UserName = "myUsername";
                options.Password = "myPassword";
                options.HiddenWindow = true;
                ClientInstance singleLFexe = lfclient.LaunchClient(options);
                IList<ClientWindow> OpenFolderBrowsers = lfclient.LaunchClient(options).GetAllClientWindows().ToList();
                EntryInfo ei = Entry.GetEntryInfo(id, mySess);
                if(ei.EntryType == EntryType.Shortcut)
                {
                    ei = Entry.GetShortcutTarget(ei.Id, mySess);
                    id = ei.Id;
                }
                
                client = OpenFolderBrowsers[0] as MainWindow;
                client.OpenDocumentById(id, oOptions);

            }
        }

The word document opens, however I'm presented with an 'Unknown Error' exception with the below details. 

   at LFSO100Lib.ILFServer.get_Version()

   at Laserfiche.OfficePlugin.Connector.App.CheckServerVersion(LFServer lfServer)

   at Laserfiche.OfficePlugin.Connector.App.CheckServerVersion(String server, Int32 port, Boolean ssl)

   at Laserfiche.OfficePlugin.Connector.App.CheckServerVersion(RepositoryAdapter connector)

   at Laserfiche.OfficePlugin.UI.LogInDialog.BeforeLogin()

   at Laserfiche.OfficePlugin.UI.ConnectorProxy.LogInDelegate(IOPConnector connector)

   at Laserfiche.OfficePlugin.UI.ConnectorProxy.ExecuteOperation(String rawMethod, Object[] args, Boolean& autoReconnect, Boolean logArgs)

   at Laserfiche.OfficePlugin.UI.ConnectorProxy.GetEntry(String path)

   at Laserfiche.OfficePlugin.Common.DocModel.OPArtifact.Create(SharingInformation sharingInfo)

   at Laserfiche.OfficePlugin.Common.DocModel.OPArtifactFactory.FromLocalDoc(String path, Boolean readOnly)

 

Any help would be much appreciated! Also for info, I'm using the latest version of Laserfiche Server, Client and SDK.

0 0

Answer

SELECTED ANSWER
replied on December 5, 2016

If you are intending to open the edoc, there are a couple workarounds:

- Open the client with HiddenWindow=false, and use the LogIn method instead of LaunchClient. This should reuse the existing client connection so that the user only sees one MainWindow.

- After calling OpenDocumentById (with HiddenWindow=true), wait a short amount of time (let's say 20 seconds). Then check if the document is locked. If so, wait in a loop for the document to be unlocked before exiting. This will keep the client open until the user is done with the document. Here is the code to check if the document is locked:

static bool IsEntryLocked(int id, Session session)
{
    EntryLockListingSettings lockListSettings = new EntryLockListingSettings();
    lockListSettings.IdentityReference = session.UserIdentity;
    lockListSettings.PersistentLocksOnly = false;

    EntryLockListing lockListing = EntryLockListing.GetListing(0, lockListSettings, session);

    for (int lockRow = 1; lockRow <= lockListing.RowCount; lockRow++)
    {
        EntryLockListingRow row = lockListing.GetRow(lockRow);
        if (row.EntryId == id)
        {
            if (row.LockLifeTime == 0)
                return false; // Checked out

            return true;
        }
    }

    return false;
}

 

0 0

Replies

replied on December 5, 2016 Show version history

Your application is closing the LF client before the LF Office Plugin can retrieve the document, when the using block goes out of scope. It needs to keep the client open until the user is done with the document. Are you intending to open the LF document viewer instead of the edoc? If so, set OpenStyle=DocumentOpenType.DocumentViewer when calling OpenDocumentById.

Note: I filed a bug report to improve the behavior when opening edocs from a hidden client window (bug# 152180).

0 0
SELECTED ANSWER
replied on December 5, 2016

If you are intending to open the edoc, there are a couple workarounds:

- Open the client with HiddenWindow=false, and use the LogIn method instead of LaunchClient. This should reuse the existing client connection so that the user only sees one MainWindow.

- After calling OpenDocumentById (with HiddenWindow=true), wait a short amount of time (let's say 20 seconds). Then check if the document is locked. If so, wait in a loop for the document to be unlocked before exiting. This will keep the client open until the user is done with the document. Here is the code to check if the document is locked:

static bool IsEntryLocked(int id, Session session)
{
    EntryLockListingSettings lockListSettings = new EntryLockListingSettings();
    lockListSettings.IdentityReference = session.UserIdentity;
    lockListSettings.PersistentLocksOnly = false;

    EntryLockListing lockListing = EntryLockListing.GetListing(0, lockListSettings, session);

    for (int lockRow = 1; lockRow <= lockListing.RowCount; lockRow++)
    {
        EntryLockListingRow row = lockListing.GetRow(lockRow);
        if (row.EntryId == id)
        {
            if (row.LockLifeTime == 0)
                return false; // Checked out

            return true;
        }
    }

    return false;
}

 

0 0
replied on December 5, 2016

Hi Robert,

 

Thank you very much for the workarounds provided! It makes sense what's going on now that you've pointed out the problem. We'll use one of the workarounds provided above until a fix has been put in place for the bug.

Thanks again,

Ronald

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

Sign in to reply to this post.