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

Question

Question

Laserfiche Session function in SDK

asked on March 3, 2015

RepositoryRegistration RepoReg = new RepositoryRegistration(LFRepoServer, LFRepoName);
Session Sess = new Session();
if (LFRepoUsername != "" | LFRepoUsername != null)
{
  Sess.LogIn(LFRepoUsername, LFRepoPassword, RepoReg);
}
else
{
 Sess.LogIn(RepoReg);
}

 

I have above code for a custom app where if user enter a username and password, then I use those values to create my session but if users doesn't enter any username and password and select a checkbox 'Windows Authentication', I use the Sess.Login(RepoReg) in else block. 

This code works fine for the if block but doesn't work for the else block and throws username and password can't be blank error.

I believe this approach works fine if we try to login to LF using LFSO83.lib functions but if I try RepositoryAccess, this doesn't run.

What am I missing?

0 0

Answer

SELECTED ANSWER
replied on March 3, 2015

Look at the call stack, it is going into Login(String userName, String password, RepositoryRegistration repository)

1 0

Replies

replied on March 3, 2015 Show version history

I think your if statement is using the wrong operator, it should be && instead of |. Also, the String class has a helpful function String.IsNullorEmpty that could make the code simpler.

1 0
replied on March 3, 2015

Hi Robert,

Thanks for the reply.

In If I am just keeping a check on LFRepoUsername which is a string. Just to be at safe side, where string could return null or an empty string like "", i am handling both scenarios.

And code does go into the right branch e.g if LFRepoUsername is not empty then it goes into If and if it is empty then it goes into Else branch BUT this is not the problem here. The problem is, in else branch I get an error "Username can not be null or empty". Error.png attached.

Error.png
Error.png (18 KB)
0 0
SELECTED ANSWER
replied on March 3, 2015

Look at the call stack, it is going into Login(String userName, String password, RepositoryRegistration repository)

1 0
replied on March 3, 2015

The following code works without error for me.

        private Session _CurSession = null;
        private Session CurSession
        {
            get
            {
                return _CurSession;
            }
            set
            {
                _CurSession = value;
            }
        }

       private void LFLogIn(string sLFServerName, string sLFRepository, string sLFUsername, string sLFPassword)
        {
            if (CurSession == null)
            {
                try
                {
                    RepositoryRegistration MyRepository = new RepositoryRegistration(sLFServerName, sLFRepository);
                    CurSession = new Session();
                    if (string.IsNullOrEmpty(sLFUsername))
                    {
                        CurSession.LogIn(MyRepository);
                    }
                    else
                    {
                        CurSession.LogIn(sLFUsername, sLFPassword, MyRepository);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

 

1 0
replied on March 3, 2015

Thanks Bert.

As I just said, code is fine, it's just the condition wasn't fully correct.

0 0
replied on March 3, 2015

That is why I recommend using the "string.IsNullOrEmpty" method.

1 0
replied on March 3, 2015

Robert, Bert,

 

Thanks guys.

I found the issue. The problem is with this: LFRepoUsername != null where code was keep going into If statement as Robert said. I took this condition away and it's now going into else and running fine.

 

Thanks for your help guys.

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

Sign in to reply to this post.