C# 获取AD(域用户)的有关问题
C# 获取AD(域用户)的问题
在C#代码里有这么一段代码
请问红色那部分表示的是什么意思,获取的是什么的属性?AD里的属性么?
------解决方案--------------------
result.Properties的类型是ResultPropertyCollection
ResultPropertyCollection.Contains:
Determines whether the property that has the specified name belongs to this collection.
------解决方案--------------------
就是判断result.Properties中是否有名字为samaccountname的propery
------解决方案--------------------
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679635(v=vs.85).aspx
在C#代码里有这么一段代码
- C# code
DirectoryEntry entry = new DirectoryEntry(path); DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = "(objectClass=*)"; searcher.PropertiesToLoad.Clear(); SearchResultCollection searchResultCollection = searcher.FindAll(); foreach (SearchResult result in resultCollection) {if ([color=#FF0000]result.Properties.Contains("samaccountname"))[/color] { ResultPropertyValueCollection resultValue = result.Properties["samaccountname"]; if (resultValue != null && resultValue.Count > 0 && resultValue[0] != null) { userName = resultValue[0].ToString(); } } }
请问红色那部分表示的是什么意思,获取的是什么的属性?AD里的属性么?
------解决方案--------------------
result.Properties的类型是ResultPropertyCollection
ResultPropertyCollection.Contains:
Determines whether the property that has the specified name belongs to this collection.
------解决方案--------------------
就是判断result.Properties中是否有名字为samaccountname的propery
------解决方案--------------------
http://msdn.microsoft.com/en-us/library/windows/desktop/ms679635(v=vs.85).aspx