public static string path = "LDAP://192.168.8.1"; public static string admin = "administrator"; public static string pwd = ""; public static DirectoryEntry createDirectoryEntry(string admin, string pwd) { DirectoryEntry ldapConnection = new DirectoryEntry(); ldapConnection.Path = path; ldapConnection.AuthenticationType = AuthenticationTypes.Secure; ldapConnection.Username = admin; ldapConnection.Password = pwd; return ldapConnection; } public static DirectoryEntry FindByName(string name) { var de = createDirectoryEntry(admin, pwd); DirectorySearcher search = new DirectorySearcher(de); search.Filter = "(cn=" + name + ")"; SearchResult result = search.FindOne(); if (result != null) return result.GetDirectoryEntry(); else return null; } public static bool SetMobile(string name, string mobile) { try { var de = FindByName(name); de.Properties["mobile"].Value = mobile; de.CommitChanges(); return true; } catch { return false; } }