2013-07-26 32 views
0

我對我的C#項目有一個簡短的任務。我想讀出我們的活動目錄,並使用此:DirectoryEntry屬性

System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry); 

foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll()) 
{ 
     System.DirectoryServices.DirectoryEntry de = resEnt.GetDirectoryEntry(); 
     try 
     { 
      myRow["eMail"] = de.Properties["Mail"].Value.ToString(); 
     } 
     catch (Exception) 
     { } 
} 

現在我想讀出其他屬性,希望你能給我的所有屬性的列表。

感謝

+1

能不能再解釋這個做呢? –

+0

請參閱[所有Active Directory屬性列表](http://msdn.microsoft.com/en-us/library/windows/desktop/ms675090%28v=vs.85%29.aspx) –

回答

6

您可以簡單地通過下面的代碼

DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry); 

      foreach (System.DirectoryServices.SearchResult resEnt in mySearcher.FindAll()) 
      { 
       try 
       { 
        foreach (string property in resEnt.Properties.PropertyNames) 
        { 
         string value = resEnt.Properties[property][0].ToString(); 

         Console.WriteLine(property + ":" + value); 
        } 
       } 
       catch (Exception) 
       { } 
      } 
+0

謝謝:)這是正是我需要的 – user2621781