Hùng Nguyễn Đức Hùng Nguyễn Đức - 1 year ago 71
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???

Answer Source

Try using :


instead of :

user.Properties["mail"].Value = null;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download