C#涓璬irectoryentry鎬庝箞浣跨敤
鍦–#涓紝DirectoryEntry绫荤敤浜庤〃绀虹洰褰曟湇鍔′腑鐨勭洰褰曢」銆備綘鍙互浣跨敤DirectoryEntry绫绘潵鍒涘缓銆佸垹闄ゃ€佷慨鏀瑰拰鎼滅储鐩綍椤广€備互涓嬫槸涓€浜涘父瑙佺殑DirectoryEntry鐨勭敤娉曠ず渚嬶細
- 鍒涘缓涓€涓柊鐨勭洰褰曢」锛?/li>
DirectoryEntry entry = new DirectoryEntry("LDAP://cn=John Doe,ou=Users,dc=example,dc=com");
entry.Properties["givenName"].Value = "John";
entry.Properties["sn"].Value = "Doe";
entry.Properties["userPrincipalName"].Value = "john.doe@example.com";
entry.CommitChanges();
- 鑾峰彇鐩綍椤圭殑灞炴€у€硷細
DirectoryEntry entry = new DirectoryEntry("LDAP://cn=John Doe,ou=Users,dc=example,dc=com");
string firstName = entry.Properties["givenName"].Value.ToString();
string lastName = entry.Properties["sn"].Value.ToString();
string email = entry.Properties["userPrincipalName"].Value.ToString();
- 淇敼鐩綍椤圭殑灞炴€у€硷細
DirectoryEntry entry = new DirectoryEntry("LDAP://cn=John Doe,ou=Users,dc=example,dc=com");
entry.Properties["givenName"].Value = "John";
entry.Properties["sn"].Value = "Smith";
entry.CommitChanges();
- 鍒犻櫎鐩綍椤癸細
DirectoryEntry entry = new DirectoryEntry("LDAP://cn=John Doe,ou=Users,dc=example,dc=com");
entry.DeleteTree();
- 鎼滅储鐩綍椤癸細
DirectoryEntry root = new DirectoryEntry("LDAP://dc=example,dc=com");
DirectorySearcher searcher = new DirectorySearcher(root);
searcher.Filter = "(objectClass=user)";
searcher.PropertiesToLoad.Add("cn");
searcher.PropertiesToLoad.Add("givenName");
searcher.PropertiesToLoad.Add("sn");
SearchResultCollection results = searcher.FindAll();
foreach (SearchResult result in results)
{
DirectoryEntry entry = result.GetDirectoryEntry();
string firstName = entry.Properties["givenName"].Value.ToString();
string lastName = entry.Properties["sn"].Value.ToString();
Console.WriteLine("Name: " + firstName + " " + lastName);
}
杩欎簺绀轰緥鍙槸DirectoryEntry绫荤殑涓€浜涘熀鏈敤娉曪紝浣犲彲浠ユ牴鎹嚜宸辩殑闇€姹傝繘涓€姝ユ帰绱㈣绫荤殑鍔熻兘銆?/p>