Suppose you have connected to Active Directory using the simple syntax:
string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com";
DirectoryEntry userEntry = Settings.GetADEntry(adPath);
Now, you find that you would like to see an attribute for that user. Let's try to display the mail attribute (which stands for email address):
Console.WriteLine("User's mail attribute is " + userEntry.Properties["mail"]);
How can I delete the mail attribute value, since setting it to an empty string will not throw an error?
It turns out to be pretty simple, albeit not very commonly used...
string adPath = "LDAP://server.domain.com/CN=John,CN=Users,dc=domain,dc=com";
DirectoryEntry userEntry = Settings.GetADEntry(adPath);
userentry.Properties["mail"].Clear();
userentry.CommitChanges();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With