Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Looping is not a good idea. I'm going to analyze that guy's code:</p> <pre><code>objGroupEntry = sr.GetDirectoryEntry(); dso = new DirectorySearcher(objGroupEntry); dso.ClientTimeout = TimeSpan.FromSeconds(30); dso.PropertiesToLoad.Add("physicalDeliveryOfficeName"); dso.PropertiesToLoad.Add("otherFacsimileTelephoneNumber"); dso.PropertiesToLoad.Add("otherTelephone"); dso.PropertiesToLoad.Add("postalCode"); dso.PropertiesToLoad.Add("postOfficeBox"); dso.PropertiesToLoad.Add("streetAddress"); dso.PropertiesToLoad.Add("distinguishedName"); dso.SearchScope = SearchScope.OneLevel; dso.Filter = "(&amp;(objectClass=top)(objectClass=person)(objectClass=organizationalPerson)(objectClass=user))"; dso.PropertyNamesOnly = false; SearchResult pResult = dso.FindOne(); if (pResult != null) { offEntry = pResult.GetDirectoryEntry(); foreach (PropertyValueCollection o in offEntry.Properties) { this.Controls.Add(new LiteralControl(o.PropertyName + " = " + o.Value.ToString() + "&lt;br/&gt;")); } } </code></pre> <p>I don't know why he's doing two searches, but let's assume there's a good reason. He should have gotten those properties from the <code>SearchResult</code>, not from the return value of <code>pResult.GetDirectoryEntry</code>, because its a completely new object.</p> <pre><code>string postalCode = pResult.Properties["postalCode"][0] as string; List&lt;string&gt; otherTelephones = new List&lt;string&gt;(); foreach(string otherTelephone in pResult.Properties["otherTelephone"]) { otherTelephones.Add(otherTelephone); } </code></pre> <p>If you insist on getting the <code>DirectoryEntry</code>, then ask for all of the properties at once with <a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.refreshcache.aspx" rel="nofollow"><code>RefreshCache</code></a>:</p> <pre><code>offEntry = pResult.GetDirectoryEntry(); offEntry.RefreshCache(propertyNameArray); </code></pre> <p>If none of that helps, look at your filters and see if you can use the <code>BaseLevel</code> scope.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload