2011-10-25 58 views
0

我有一個Active Directory用戶DirectoryEntries的集合,我需要獲取與每個相關的街道地址。我使用的線沿線的東西:檢索Active Directory DirectoryEntry的街道地址屬性

bool TryGetPropertyValue(DirectoryEntry de, string propertyName, out string propertyValue) 
    { 
     if (de.Properties.Contains(propertyName) && de.Properties[propertyName].Count > 0) 
     { 
      propertyValue = de.Properties[propertyName][0].ToString(); 
      return true; 
     } 
     propertyValue = string.Empty; 
     return false; 
    } 

但我找不到propertyName值就會得到用戶的地址。有人存在嗎,還是有另一種獲得這些信息的方式?

+0

請看看http://stackoverflow.com/questions/5058261/how-to-get-update-contacts-within-active-directory – Tariqulazam

+1

「Address」,「Address-Home」,「Registered-Address 「和」街道地址「是Windows AD中用戶類的地址相關項目,您可以嘗試其中一種。完整的列表可以在這裏找到:http://msdn.microsoft.com/en-us/library/ms683980(v=VS.85).aspx – Falle1234

回答

3

小心你得到的方式DirectoryEntry de。在純LDAP的角度來看,最好在目錄搜索過程中指定您真正想要檢索的屬性。我知道,大多數developpers的假設所有屬性應該是retreive,但看的LDAP點就不是那麼明顯:

/* Connection to Active Directory 
*/ 
string sFromWhere = "LDAP://WM2008R2ENT:389/dc=dom,dc=fr"; 
DirectoryEntry deBase = new DirectoryEntry(sFromWhere, "dom\\jpb", "root.123"); 

DirectorySearcher dsLookFor = new DirectorySearcher(deBase); 
dsLookFor.Filter = "(CN=user1 Users)"; 
dsLookFor.SearchScope = SearchScope.Subtree; 
dsLookFor.PropertiesToLoad.Add("cn"); 
// Add one line for each property you need. 
dsLookFor.PropertiesToLoad.Add("..."); 


SearchResultCollection srcUsers = dsLookFor.FindAll(); 

在視圖屬性名點,你最好參考Active Directory Schema和specialy All atributes

爲了將屬性與用戶和計算機活動目錄MMC中的輸入字段鏈接起來,您可以使用LDP.EXE(W2K8中的本機文件,並且來自W2K3中的資源工具包)。另一個有趣的工具是Apache Directory Studio。它適用於所有平臺(Linux(MAC),Microsoft),並允許您瀏覽目錄和架構。

相關問題