Hùng Nguyễn Đức Hùng Nguyễn Đức - 7 months ago 31
C# Question

Update value Ad attribute to null or empty get errror?

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;

"The attribute syntax specified to the directory service is invalid."

How can i set Value of some properties to null or empty???


Try using :


instead of :

user.Properties["mail"].Value = null;