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

Question

Question

Does not exist in the current context

SDK
asked on August 13, 2014

 Greetings,

this issue has more to do with the fact that I am transitioning to C#.net from VB.net.  I have successfully logged into LaserFiche using the following function call and function;

 

Call:

// ====== Login to Laserfiche ====== 8/13/2014

bool loginStatus = LFLoginRA(Properties.Settings.Default.LFServerName, Properties.Settings.Default.LFRepositoryName, Properties.Settings.Default.LFUserID, Properties.Settings.Default.LFPassword);

 

Function:

public bool LFLoginRA(string LFServerName, string LFRepositoryName, string LFUserID, string LFPassword)

{

// Using the overloaded RepositoryRegistration constructor

RepositoryRegistration myRepoReg = new RepositoryRegistration(LFServerName, LFRepositoryName);

Session mySess = new Session();

mySess.LogIn(LFUserID, LFPassword, myRepoReg);

return true;

 

The problem is when I go to create a folder, the error says that the mySess Does not exist in the current context.  I am calling this from within a for each loop.

 

Here is the call;

 

Dynamicfolder(lfFolderPath,mySess); mySess is where the error is encountered.  this is the only error I am getting.

 

Here is the sub;

 

public static void Dynamicfolder(string FolderPath,Session mySess)

{

try

{

// Checks to see if a folder with the desired name

// already exists.

FolderInfo FI = Folder.GetFolderInfo(FolderPath, mySess);

}

 

 

catch (LaserficheRepositoryException ex)

{

// Creates the folder if the error code indicates

// that it doesn't exist.

if (ex.ErrorCode == 9001) //"Entry not found"

{

Folder.Create(Folder.GetFolderInfo(FolderPath, mySess), "Subfolder", EntryNameOption.None, mySess);

}

}

 

If this were VB I would think it has to do with session mySess not being a global variable.

 Any help you can provide would be great.

 

Phil

0 0

Answers

APPROVED ANSWER
replied on August 13, 2014

Hi Phil,

 

From the looks of it, your variable is no longer in scope by the time you get to that call. C# doesn't have global variables, only static, instance or local variables. So in order to keep mySess around you're going to have to either return it from your function, or store it somewhere. Check out the MSDN article on Scopes in C# for more information.

0 0
SELECTED ANSWER
replied on August 15, 2014

Hi Phil, 

 

If your question has been answered, please let us know by clicking the "This answered my question" button on the response.

 

If you still need assistance with this matter, just update this thread. Thanks!

0 0
replied on August 18, 2014

Thanks for the direction Mathew, I now understand c# scope.

0 0

Replies

replied on August 13, 2014 Show version history

Could it be because you are creating the mySess variable within the function? It should be global and therefore should be declared outside of the function if you wish to use it elsewhere.

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

Sign in to reply to this post.