using System.DirectoryServices; // Connect to a directory entry DirectoryEntry entry = new DirectoryEntry("LDAP://dc=mydomain,dc=com"); // Access properties of the directory entry Console.WriteLine(entry.Properties["distinguishedName"].Value.ToString()); // Create a new user object DirectoryEntry user = entry.Children.Add("CN=John Smith", "user"); // Set properties of the user object user.Properties["givenName"].Value = "John"; user.Properties["sn"].Value = "Smith"; user.Properties["userPrincipalName"].Value = "[email protected]"; user.Properties["sAMAccountName"].Value = "jsmith"; // Save the user object to the directory user.CommitChanges();In this example, we connect to a directory entry by specifying the LDAP path, and access properties of the entry. We then create a new user object under the directory entry, set properties of the user object, and save the user object to the directory. The System.DirectoryServices namespace is part of the .NET Framework Class Library.