Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update value Ad attribute to null or empty get errror?

Tags:

c#

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???

like image 344
Hùng Nguyễn Đức Avatar asked Jun 06 '15 10:06

Hùng Nguyễn Đức


1 Answers

Try using :

user.Properties["mail"].Clear() 

instead of :

user.Properties["mail"].Value = null;
like image 144
Oleg Avatar answered Oct 09 '22 01:10

Oleg