Sorry that I hardcoded the user’s data, I hope it is Ok for the purpose of a sample showing the process. Also, we will need to assign some role and some vault for the new user, this will require to find the IDs of the respective objects.

Here is our new method called AddUser():

// Add a new user.

// Let it be me with the 'Adminstrator' role and access to

// the vault called 'MaratVault'.

//===============================================================

publicstaticvoid AddUser()

{

using (MyVaultServiceManager mgr = newMyVaultServiceManager(

MyVaultServiceManager.Mode.ReadWrite))

{

try

{

// Let's find the 'Administrator' role

//------------------------------------------------------

Role[] roles = mgr.Services.AdminService.GetAllRoles();

Role admin = FindRole(roles, "Administrator");

if( admin == null )

{

MessageBox.Show("FindRole() failed.");

return;

}

long[] roleIdArray = newlong[] { admin.Id };

// I want to provide the user access to the vault called

// "MaratVault". So, let's find that vault Id:

//---------------------------------------------------------

KnowledgeVault vault = mgr.Services.KnowledgeVaultService.

GetKnowledgeVaultByName("MaratVault");

long[] vaultIdArray = newlong[] { vault.Id };

// Now create the user

//---------------------------------------------------------

User newUser = mgr.Services.AdminService.AddUser(

"MaratM", // user name

"123456", // password

AuthTyp.Vault, // authentication - not Active Directory

"Marat", // first name

"Mirgaleev", // last name

"email", // email address

true, // is active

roleIdArray, // which roles

vaultIdArray); // which vaults

}

catch (System.Exception err)

{

MessageBox.Show("Probably, a user name conflict.\n"

+ "The user name may already exist.\n\n"

+ err.ToString(), "Error");

} // try

} // using

} // AddUser()

You may have noticed that we connect to Vault in the ‘Read-and-Write’ mode only if we need to change or add some information.

Sorry that I hardcoded the user’s data, I hope it is Ok for the purpose of a sample showing the process. Also, we will need to assign some role and some vault for the new user, this will require to find the IDs of the respective objects.

Here is our new method called AddUser():

// Add a new user.

// Let it be me with the 'Adminstrator' role and access to

// the vault called 'MaratVault'.

//===============================================================

publicstaticvoid AddUser()

{

using (MyVaultServiceManager mgr = newMyVaultServiceManager(

MyVaultServiceManager.Mode.ReadWrite))

{

try

{

// Let's find the 'Administrator' role

//------------------------------------------------------

Role[] roles = mgr.Services.AdminService.GetAllRoles();

Role admin = FindRole(roles, "Administrator");

if( admin == null )

{

MessageBox.Show("FindRole() failed.");

return;

}

long[] roleIdArray = newlong[] { admin.Id };

// I want to provide the user access to the vault called

// "MaratVault". So, let's find that vault Id:

//---------------------------------------------------------

KnowledgeVault vault = mgr.Services.KnowledgeVaultService.

GetKnowledgeVaultByName("MaratVault");

long[] vaultIdArray = newlong[] { vault.Id };

// Now create the user

//---------------------------------------------------------

User newUser = mgr.Services.AdminService.AddUser(

"MaratM", // user name

"123456", // password

AuthTyp.Vault, // authentication - not Active Directory

"Marat", // first name

"Mirgaleev", // last name

"email", // email address

true, // is active

roleIdArray, // which roles

vaultIdArray); // which vaults

}

catch (System.Exception err)

{

MessageBox.Show("Probably, a user name conflict.\n"

+ "The user name may already exist.\n\n"

+ err.ToString(), "Error");

} // try

} // using

} // AddUser()

You may have noticed that we connect to Vault in the ‘Read-and-Write’ mode only if we need to change or add some information.