This section contains information about how to add a new entry inside a directory using classes provided by Novell.Directory.Ldap namespace. To add a new directory entry, use the Add function of LdapConnection class.
Adding an entry involves four steps:
Create the attributes of the entry and add them to an attribute set.
Specify the DN of the entry to be created.
Create an LdapEntry object with the DN and the attribute set.
Call the LdapConnection.Add method to add it to the directory.
The C# code fragments below shows how to add an entry using Novell.Directory.Ldap namespace:
// C# Library namespace using Novell.Directory.Ldap;
// Creating an LdapConnection instance LdapConnection ldapConn= new LdapConnection();
//Connect function will create a socket connection to the server ldapConn.Connect(ldapHost,ldapPort);
//Bind function will Bind the user object Credentials to the Server ldapConn.Bind(userDN,userPasswd);
//Creates the List attributes of the entry and add them to attribute set LdapAttributeSet attributeSet = new LdapAttributeSet(); attributeSet.Add( new LdapAttribute( "objectclass","inetOrgPerson")); attributeSet.Add( new LdapAttribute("cn", new string[]{"James Smith", "Jimmy Smith"})); attributeSet.Add( new LdapAttribute("givenname", "James")); attributeSet.Add( new LdapAttribute("sn", "Smith")); attributeSet.Add( new LdapAttribute("mail", "JSmith@Acme.com"));
// DN of the entry to be added string dn = "cn=KSmith," + containerName; LdapEntry newEntry = new LdapEntry( dn, attributeSet );
//Add the entry to the directory ldapConn.Add( newEntry );