Here code to update mail, department, title and mobile to null or empty value of AD user.
var adSearch = new DirectorySearcher(ConnectHelper.ContxEntry);
adSearch.Filter = "samAccountName=" + "....";
var result = adSearch.FindOne();
if (result != null)
{
DirectoryEntry user = result.GetDirectoryEntry();
user.Properties["mail"].Value = null;
user.Properties["Department"].Value = null;
user.Properties["Title"].Value = null;
user.Properties["mobile"].Value = null;
user.CommitChanges();
}
Error: "The attribute syntax specified to the directory service is invalid."
How can i set Value of some properties to null or empty???
Try using :
user.Properties["mail"].Clear()
instead of :
user.Properties["mail"].Value = null;
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