<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>.Net and Directory Services Programming</title>
        <link>http://www.msftliveblogs.com/mhamilton/category/5.aspx</link>
        <description>.Net and Directory Services Programming</description>
        <language>en-US</language>
        <copyright>Michael J. Hamilton, Sr.</copyright>
        <managingEditor>mike@mjhamilton.com</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <item>
            <title>.Net Directory Services Programming - C# - Part 3</title>
            <link>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-3.aspx</link>
            <description>&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;u&gt;.Net Directory Services Programming – C# - Part 3 &lt;/u&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;u&gt;&lt;/u&gt;      &lt;p&gt;&lt;span style="text-decoration: none"&gt; &lt;/span&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Topics&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;DirectorySearcher – the other critical class in the DirectoryServices namespace.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Review&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Because a lot of your Directory Services (DS) development will involve querying DS for data, it makes sense that this is a powerful class offered in the namespace, and below are some of the features:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;ul style="margin-top: 0in" type="disc"&gt;   &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DirectorySearcher&lt;/b&gt; – Performs the initial queries against AD &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;SearchResult&lt;/b&gt; – A single object reference from a search performed by &lt;i style="mso-bidi-font-style: normal"&gt;DirectorySearcher&lt;/i&gt; &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;ResultPropertyCollection&lt;/b&gt; – A collection of properties of the &lt;i style="mso-bidi-font-style: normal"&gt;SearchResult&lt;/i&gt; instance &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;ResultPropertyValueCollection &lt;/b&gt;– The values of properties in a &lt;i style="mso-bidi-font-style: normal"&gt;SearchResult&lt;/i&gt; instance. &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;SearchResultCollection&lt;/b&gt; – Basically a collection of &lt;i style="mso-bidi-font-style: normal"&gt;SearchResult&lt;/i&gt; instances returned from a query by &lt;i style="mso-bidi-font-style: normal"&gt;DirectorySearcher&lt;/i&gt; &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo1"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;SortOption&lt;/b&gt; – Allows a means to sort a result set. &lt;/li&gt; &lt;/ul&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;We have briefly touched on DS by introducing some basic DirectoryEntry information and a couple simple examples, and we have introduced some basic properties and examples on how to interact with those.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;I have not taken a lot of time to review a directory structure – basically assuming that you should have some of this understanding already. As I delve into the next lesson, this assumption holds fast. If you have any issues or are dealing with something that I am not elaborating enough on, please feel free to email me directly at (mikeh AT thedataworks.net) and I will respond as quickly as I can. Please forgive the notation there – but we all are familiar with the latest in SPAM bots and whatnot.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Show me the Money!!!&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Or at least the code. Lets get started…&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Parent – Child Relationships&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;DirectoryEntry objects (DE’s) can be a root object in AD, or an object within another – hence, a child object of another. We reviewed in Part 1 a few of the common references to object types (CN, &lt;place w:st="on"&gt;&lt;city w:st="on"&gt;OU&lt;/city&gt;, &lt;state w:st="on"&gt;DC&lt;/state&gt;&lt;/place&gt;). These are the most prevalent you will deal with.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;DC is the root level context. OU’s can be off the root, or a child of other OU’s and even Containers. CN’s can be off the root, within OU’s and often are found within Containers.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;A word about Containers and Security&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;When planning your DS application, keep this in mind: Containers are non-secure objects! Let me explain. AD security is multi-faceted, yes, but the real security is managed using Group Policy (something we are not going to review here). &lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Containers are basically folders in your directory tree. AD comes with a couple by default. If you promote a server and check your directory tree, you’ll find a Users, a Built-In, and a couple other folders off the root tree (or context/server name) object. These are &lt;i style="mso-bidi-font-style: normal"&gt;not&lt;/i&gt; OU’s – they are containers.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Group Policy (GP) cannot be applied to a Container object in AD. You can apply GP to objects within Containers – depending on what those objects are – but not the Container itself. This is important because a lot of administration can be simplified by applying the GP to the entire Container. So if not the Container, then what? Organizational Units – OU’s. Alas, OU’s are going to be your preferred &lt;i style="mso-bidi-font-style: normal"&gt;folder&lt;/i&gt; or &lt;i style="mso-bidi-font-style: normal"&gt;container&lt;/i&gt; (for lack of a better way to put it) for object storage.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Basic Searches&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;In Part 1 we introduced a server name and basic OU’s. To re-cap that:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Server:&lt;/b&gt; developer.hamilton.com&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;OU=Accounts&lt;/b&gt; – off the root of developer.hamilton.com&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;OU=Developers&lt;/b&gt; – within the OU=Accounts&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;CN=Mike Hamilton&lt;/b&gt; – within the OU=Developers&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Within the OU=Accounts I might also create &lt;i style="mso-bidi-font-style: normal"&gt;service accounts&lt;/i&gt; – basic user accounts that are used to run services such as IIS Application Pools, SQL Server, or other server / service applications. I might also have OU’s that represent other departments that pertain to development: BA’s for the Business Analyst, QA’s, etc. You can nest OU’s and accounts in just about any way you want to. NOTE: In AD – if you have not already – you will run into one of the inherent limitations of the AD Users &amp;amp; Computers (dsa.msc) snap-in: It can only display the first 2,000 objects within a Container or OU. So if you anticipate a large volume of users for a system you are designing, keep this in mind. You will want to present 1) a more suitable customized user interface piece for administration of this DS, or 2) design your object hierarchy so that users are more spread out within the DS. I will touch base on this topic in a later Part and introduce a couple ideas for addressing this limitation.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DirectorySearcher&lt;/b&gt; and the &lt;b style="mso-bidi-font-weight: normal"&gt;SearchResult&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;When using the DirectorySearcher class, you have the &lt;b style="mso-bidi-font-weight: normal"&gt;FindOne()&lt;/b&gt; and &lt;b style="mso-bidi-font-weight: normal"&gt;FindAll()&lt;/b&gt; methods that build your result set. As they infer, one finds one occurrence, the other finds all occurrences.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Let’s say I had more than one Mike on my team, and I wanted to find all entries that began with &lt;i style="mso-bidi-font-style: normal"&gt;Mike&lt;/i&gt;?&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry();&lt;span style="mso-tab-count: 2"&gt;                &lt;/span&gt;// Binds root context &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Now find every CN that has Mike at the beginning of the name… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher searcherResults = new DirectorySearcher(rootEntry,”(CN=Mike*)”);&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;This is a simple example, and the result set will be one or more object references that begin with Mike. Notice that I did a bind on the root of the DS. I could have narrowed the focus of the search to only the developer’s OU by doing the following:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry developersEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/OU=Accounts,OU=Developers,DC=developer,DC=&lt;place w:st="on"&gt;&lt;city w:st="on"&gt;hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;&lt;/place&gt;=com”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;This would return an entry object where the parent would be the OU=Developers, and not the default root of the DS tree.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Lets say my DS was structured like the following:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;developer.hamilton.com&lt;/b&gt; &lt;span style="font-family: wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;à&lt;/span&gt;&lt;/span&gt; root of the DS&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;OU=Accounts&lt;/b&gt; &lt;span style="font-family: wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;à&lt;/span&gt;&lt;/span&gt; First OU of accounts of users.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;OU=Developers&lt;/b&gt; &lt;span style="font-family: wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;à&lt;/span&gt;&lt;/span&gt; Key development personnel&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;OU=Bas&lt;/b&gt; &lt;span style="font-family: wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;à&lt;/span&gt;&lt;/span&gt; Business Analyst&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;OU=QA&lt;/b&gt; &lt;span style="font-family: wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;à&lt;/span&gt;&lt;/span&gt; Quality Assurance / Test personnel&lt;b style="mso-bidi-font-weight: normal"&gt; &lt;/b&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;OU=Users&lt;/b&gt; &lt;span style="font-family: wingdings; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'; mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;&lt;span style="mso-char-type: symbol; mso-symbol-font-family: wingdings"&gt;à&lt;/span&gt;&lt;/span&gt; General users on this server.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Now, we want to find all users that are in the &lt;b style="mso-bidi-font-weight: normal"&gt;Users&lt;/b&gt; OU, not returning the developers or other personnel within the directory. That’s pretty straight forward.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry developersEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/OU=Accounts,OU=Users,DC=developer,DC=&lt;place w:st="on"&gt;&lt;city w:st="on"&gt;hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;&lt;/place&gt;=com”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Now return all users in this OU… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher searcherResults = new DirectorySearcher(rootEntry,”(CN= *)”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;As you get more familiar with DS programming, you will find there are other ways to accomplish the same result – I am simply trying to open those doors for you.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;It is important that you understand how to narrow your search filter in this way because you will find it greatly improves the performance of your application when you know where to search for content and you keep your search filter narrowly defined. For example, if I have 15,000 employees, they would very likely be grouped in AD by their department, and possibly further grouped by sub-departments. I would want to know this information beforehand so I can plan my DS application to be as efficient as possible. I would not want to search the rootDSE each time for a given employee or group of employees, if I know the departments those employees are in.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;More on the Search Filter&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The &lt;i style="mso-bidi-font-style: normal"&gt;filter&lt;/i&gt; is a LDAP string that allows you to search for objects based on specific criteria. You will also use relational operators to better refine your search. The following list those operators:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;=&lt;span style="mso-tab-count: 2"&gt;                      &lt;/span&gt;Equal to &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;~=&lt;span style="mso-tab-count: 2"&gt;                    &lt;/span&gt;Is &lt;i style="mso-bidi-font-style: normal"&gt;approximately&lt;/i&gt; equal to (or like) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&amp;lt;=&lt;span style="mso-tab-count: 2"&gt;                    &lt;/span&gt;Less than or equal to &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&amp;gt;=&lt;span style="mso-tab-count: 2"&gt;                    &lt;/span&gt;Greater than or equal to &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;NOTE: You cannot use ‘&amp;lt;’ or ‘&amp;gt;’ individually in LDAP – you must use the notation &amp;lt;= or &amp;gt;=. &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The * character works as a wildcard in your search, as in the example above we searched for CN=Mike* or CN=* - in this case, get all Canonical (common) Names beginning with Mike, or get all names period (respectively).&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;To find all users with a surname of Hamilton you would use&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;(sn = Hamilton) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;To find all users where the email ends in @hamilton.com&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;(&amp;amp;(objectCategory = person) (objectClass = user) (mail = &lt;a href="mailto:*@hamilton.com)"&gt;&lt;span style="text-decoration: none; text-underline: none"&gt;*@hamilton.com)&lt;/span&gt;&lt;/a&gt;) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Notice the Polish notation used here – the operator comes before the condition. LDAP uses this notation in the Filter. The above example would be more familiar possibly as&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;(objectCategory = person) AND (objectClass = user) AND (mail = &lt;a href="mailto:*@hamilton.com"&gt;&lt;span style="text-decoration: none; text-underline: none"&gt;*@hamilton.com&lt;/span&gt;&lt;/a&gt;) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The following are allowed logical operators:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&amp;amp;&lt;span style="mso-tab-count: 1"&gt;         &lt;/span&gt;AND &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;|&lt;span style="mso-tab-count: 1"&gt;           &lt;/span&gt;OR &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;!&lt;span style="mso-tab-count: 1"&gt;           &lt;/span&gt;NOT &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;You set the &lt;i style="mso-bidi-font-style: normal"&gt;filter&lt;/i&gt; for a search using the DirectorySearcher.Filter property. The following code will create a binding to the root context, and return everything from the root down:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry();&lt;span style="mso-tab-count: 2"&gt;                &lt;/span&gt;// Binds root context &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(rootEntry); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Let’s say we have a binding to the rootDSE as above, but only want to return all users with a surname of Hamilton? Change the DirectorySearcher to the following:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(“(sn=Hamilton)”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;You can either pass the DirectoryEntry object, or you can specify a filter in this fashion when creating a DirectorySearcher instance.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Loading Specific Properties&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;By default, when you create a DirectorySearcher instance, you return &lt;i style="mso-bidi-font-style: normal"&gt;all&lt;/i&gt; properties for that binding (which can be a lot of data if you have a lot of items in your returned result set).&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;You can refine your result set by specifying the exact properties to be returned. This is especially important when you could be returning large collections of users.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Following the above example I could create my rootSearcher and then do:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“name”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“sn”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“mail”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“telephoneNumber”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Here I have specifically limited the result set to only include the &lt;i style="mso-bidi-font-style: normal"&gt;name, sn (surname), mail and telephoneNumber&lt;/i&gt; properties.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Finally, when we define our searcher, we can stipulate the &lt;i style="mso-bidi-font-style: normal"&gt;search scope&lt;/i&gt;. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Search Scope&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The search scope determines the extent of the search in a directory, defaulting to beginning at the &lt;i style="mso-bidi-font-style: normal"&gt;root&lt;/i&gt;. &lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;In the &lt;b style="mso-bidi-font-weight: normal"&gt;System.DirectoryServices.SearchScope&lt;/b&gt; you will find the following 3 enumerations specified:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Base&lt;/b&gt; – Limits the scope to the base, or only 1 object.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;OneLevel&lt;/b&gt; – Searches 1 level of the immediate child objects, excluding the base object.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Subtree&lt;/b&gt; – Searches all child objects under the base object, including the base object.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;When creating a DirectorySearcher instance, the following table lists &lt;i style="mso-bidi-font-style: normal"&gt;default&lt;/i&gt; constructor behaviors:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;table class="MsoTableGrid" style="border-right: medium none; border-top: medium none; border-left: medium none; border-bottom: medium none; border-collapse: collapse; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-yfti-tbllook: 1184" cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;     &lt;tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;       &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: black 1pt solid; padding-left: 5.4pt; padding-bottom: 0in; border-left: black 1pt solid; width: 2.05in; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;PROPERTY &lt;/b&gt;            &lt;/p&gt;&lt;p&gt;&lt;/p&gt;                   &lt;p&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: black 1pt solid; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DEFAULT VALUE &lt;/b&gt;            &lt;/p&gt;&lt;p&gt;&lt;/p&gt;                   &lt;p&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; border-top: black 1pt solid; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DESCRIPTION&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="mso-yfti-irow: 1"&gt;       &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; border-left: black 1pt solid; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;SearchRoot&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Null&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Searches the root of the domain controller (rootDSE).&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="mso-yfti-irow: 2"&gt;       &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; border-left: black 1pt solid; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Filter&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;(objectClass=*)&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The search retrieves all objects.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="mso-yfti-irow: 3"&gt;       &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; border-left: black 1pt solid; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;PropertiesToLoad&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;An empty string array&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The search retrieves all properties.&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="mso-yfti-irow: 4"&gt;       &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; border-left: black 1pt solid; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;SearchScope&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Subtree&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The search will be performed on the complete subtree of the base object (or entire domain in this case).&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="mso-yfti-irow: 5; mso-yfti-lastrow: yes"&gt;       &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0in; border-left: black 1pt solid; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;          &lt;p&gt; &lt;/p&gt;          &lt;p&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;          &lt;p&gt; &lt;/p&gt;          &lt;p&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td style="border-right: black 1pt solid; padding-right: 5.4pt; padding-left: 5.4pt; border-left-color: #eeeeee; padding-bottom: 0in; width: 2.05in; border-top-color: #eeeeee; padding-top: 0in; border-bottom: black 1pt solid; background-color: transparent; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-alt: solid black .5pt; mso-border-left-themecolor: text1; mso-border-top-alt: solid black .5pt; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" valign="top" width="197"&gt;         &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;          &lt;p&gt; &lt;/p&gt;          &lt;p&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Constructors of the DirectorySearcher Class&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The above table displays the default constructor when you create a DirectorySearcher instance like:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt;  &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry();&lt;span style="mso-tab-count: 2"&gt;                &lt;/span&gt;// Binds root context &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(rootEntry); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The above specifies the &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;Search Root&lt;/i&gt;&lt;/b&gt;.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Specifying the Filter Only&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;We showed this earlier, &lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(“(sn=Hamilton)”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Specifying the Search Root and Filter&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Create our base / root reference:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/OU=Accounts,OU=Developers,DC=developer.DC=Hamilton,DC=com”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Now specify the filter… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearch rootSearcher = new DirectorySearcher(rootEntry, “(sn=Hamilton)”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Specifying the Filter and a List of Properties to load&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Create the set of properties to load… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;string [] searchProperties = new string[4]; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchProperties[0] = “name”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchProperties[1] = “sn”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchProperties[2] = “mail”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchProperties[3] = “telephoneNumber”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Get all users that have an email ending in hamilton.com… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(“(mail=*hamilton.com)”, searchProperties); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The above example will return &lt;i style="mso-bidi-font-style: normal"&gt;all&lt;/i&gt; users from the rootDSE with an email ending in hamilton.com. Let’s refine that.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Specifying the Root, Search Filter, and Properties to Load&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Specify the properties to load… Here we get Full Name, Company, Phone… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;string [] searchProperties = new string[3]; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchProperties[0] = “name”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchProperties[1] = “co”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchProperties[2] = “telephoneNumber”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Now bind to a more refined root – developers only… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/OU=Accounts,OU=Developers,DC=developer,DC=hamilton,DC=com”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// No get all users from this root with an email ending in hamilton.com… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(rootEntry, “(mail=*hamilton.com)”, searchProperties); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;You should have a better idea now how to use the various constructors of the DirectorySearcher class.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Methods of the DirectorySearcher&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;When you have created a binding and set filter values, you will use 1 of the 2 DirectorySearcher methods:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;FindOne()&lt;/b&gt; – Returns the first, and only 1 object of the search criteria.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;FindAll()&lt;/b&gt; – Returns a &lt;i style="mso-bidi-font-style: normal"&gt;SearchResultCollection&lt;/i&gt; of all objects that matched the search criteria.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;We’ll do a brief sample for each method and wrap up this series with the Sorter class.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Return using FindOne()&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-spacerun: yes"&gt; &lt;/span&gt; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// The following demonstrates that FindOne() returns only the first entry that matches the search critieria… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/OU=Accounts,OU=Developers,DC=developer,DC=hamilton,DC=com”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(rootEntry); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// What to search for… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.Filter = “(CN=*)”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Specific properties to load… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“name”);&lt;span style="mso-tab-count: 2"&gt;                      &lt;/span&gt;// Full name… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“mail”);&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;// Primary email addy… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“telephoneNumber”);&lt;span style="mso-tab-count: 1"&gt;  &lt;/span&gt;// Phone #... &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;SearchResult searchResults = rootSearcher.FindOne(); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Extract out the properties returned and display in a console… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;ResultPropertyCollection propertiesCollection; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;propertiesCollection = searchResults.Properties; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Cycle through and display (or add to a listbox, etc)… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;Foreach (string currentProperty in propertiesCollection.PropertyNames) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;foreach (Object thisCollection in propertiesCollection[currentProperty]) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;Console.WriteLine(currentProperty + “ = “ + thisCollection); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Return using FindAll()&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Unlike above, the &lt;i style="mso-bidi-font-style: normal"&gt;ResultPropertyCollection&lt;/i&gt; being returned with FindOne(), &lt;b style="mso-bidi-font-weight: normal"&gt;FindAll()&lt;/b&gt; comes back in a &lt;i style="mso-bidi-font-style: normal"&gt;SearchResultCollection&lt;/i&gt; object.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;We would process the result set similar to the following:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Get all objects returned… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;foreach (SearchResult searchResults in rootSearcher.FindAll()) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;{&lt;span style="mso-tab-count: 1"&gt;          &lt;/span&gt;// Process… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;foreach (string propertName in searchResults.Properties.PropertyNames) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;foreach (Object retEntry in searchResults.Properties[propertyName]) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 3"&gt;                                    &lt;/span&gt;Console.WriteLine(propertyName + “ = “ + retEntry); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;Console.WriteLine(“”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;If the root of the search is not properly set, a &lt;i style="mso-bidi-font-style: normal"&gt;InvalidOperationException&lt;/i&gt; exception will be thrown. Also, if the provider you are trying this against is not supported, a &lt;i style="mso-bidi-font-style: normal"&gt;NotSupportedException&lt;/i&gt; exception is thrown.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Sorting the Result Sets&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Finally, the &lt;i style="mso-bidi-font-style: normal"&gt;SortOption&lt;/i&gt; class specifies how to sort the result set of a search. The class also allows you to specify either ascending or descending sort order.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Let’s do a search on all users that have an email ending in @hamilton.com and that exist in the Developers OU. Further, restrict the properties returned, sort the list, and using the code snippet above, list the results in a console window.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/OU=Accounts,OU=Developers,DC=developer,DC=hamilton,DC=com”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectorySearcher rootSearcher = new DirectorySearcher(rootEntry); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Set our search filter and properties to load… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.Filter = “(mail=*hamilton.com)”; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“name”);&lt;span style="mso-tab-count: 1"&gt;          &lt;/span&gt;// Full name… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“mail”);&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;// Primary email addy… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.PropertiesToLoad.Add(“telephoneNumber”);&lt;span style="mso-tab-count: 1"&gt;  &lt;/span&gt;// Phone #... &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Now sort the result set… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;SortOption sortedResults = new SortOption(); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;sortedResults.PropertyName = “name”;&lt;span style="mso-tab-count: 2"&gt;                     &lt;/span&gt;// Sort by full name… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;sortedResults.Direction.SortDirection.Ascending; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Perform the search and output the results.. &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;rootSearcher.Sort = sortedResults; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;foreach (SearchResult searchResults in rootSearcher.FindAll()) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;{&lt;span style="mso-tab-count: 1"&gt;          &lt;/span&gt;// Process… &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;foreach (string propertName in searchResults.Properties.PropertyNames) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;foreach (Object retEntry in searchResults.Properties[propertyName]) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 3"&gt;                                    &lt;/span&gt;Console.WriteLine(propertyName + “ = “ + retEntry); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;Console.WriteLine(“”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Final notes on the following classes: &lt;i style="mso-bidi-font-style: normal"&gt;SearchResult, SearchResultCollection, ResultPropertyCollection,&lt;/i&gt; and&lt;i style="mso-bidi-font-style: normal"&gt; ResultPropertyValueCollection&lt;/i&gt;. &lt;/b&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;/b&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;SearchResult&lt;/i&gt;&lt;/b&gt; class consist of the first entry returned during a search. It retrieves the data from the &lt;i style="mso-bidi-font-style: normal"&gt;SearchResultCollection&lt;/i&gt;, and the &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;FindOne()&lt;/i&gt;&lt;/b&gt; method of the DirectorySearcher class returns an instance of the &lt;i style="mso-bidi-font-style: normal"&gt;SearchResult&lt;/i&gt; class.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;SearchResultCollection&lt;/i&gt;&lt;/b&gt; class is actually a collection of &lt;i style="mso-bidi-font-style: normal"&gt;SearchResult&lt;/i&gt; instances and these are returned using the &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;FindAll()&lt;/i&gt;&lt;/b&gt;&lt;i style="mso-bidi-font-style: normal"&gt; &lt;/i&gt;method of the DirectorySearcher class. You use the &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;Count&lt;/i&gt;&lt;/b&gt; property to get the number of items returned in the collection. Use the &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;Item&lt;/i&gt;&lt;/b&gt; property to index through the &lt;i style="mso-bidi-font-style: normal"&gt;SearchResultCollection&lt;/i&gt; to enumerate each property. Finally, the &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;PropertiesLoaded&lt;/i&gt;&lt;/b&gt; property returns a string array containing the names of the properties loaded for the original search criteria.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;ResultPropertyCollection&lt;/i&gt;&lt;/b&gt; class is accessed as a &lt;b style="mso-bidi-font-weight: normal"&gt;Properties&lt;/b&gt; property of the &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;SearchResult&lt;/i&gt;&lt;/b&gt; class. It has an &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;Item&lt;/i&gt;&lt;/b&gt; property you use to index the collection, which is a string value. This index retrieves the values of the property matching the specified index name as a &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;ResultPropertyValueCollection&lt;/i&gt;&lt;/b&gt;. The following snippet will demonstrate getting all returned properties and outputting the result to a console window:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DirectoryEntry rootEntry = new DirectoryEntry(); // Entire domain… &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;DireectorySearcher rootSearcher = new DirectorySearcher(rootEntry, “(sn=Hamilton)”); &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;      &lt;p&gt; &lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;SearchResult searchResults = rootSearcher.FindOne(); &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;      &lt;p&gt; &lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Get the properties returned… &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;ResultPropertyCollection propertyCollection = &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt; &lt;/span&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;searchResults.Properties; &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;      &lt;p&gt; &lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;// Output… &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;foreach (string thisProperty in propertyCollection.PropertyNames) &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;{ &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;foreach (Object propertyValue in propertyCollection[thisProperty]) &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;{ &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 2"&gt;                        &lt;/span&gt;Console.WriteLine(thisProperty + “ = “ + propertyValue); &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;} &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;} &lt;/span&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #1f497d; mso-themecolor: text2"&gt;&lt;/span&gt;      &lt;p&gt; &lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;In the future I will introduce ADSI API and application code and we will see about developing a small application that will take some of what we have reviewed in these three parts and create a directory browser sample application.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;I want to note that for the sample code so far, if you are not executing this on an actual AD domain controller, you will need to change the &lt;b style="mso-bidi-font-weight: normal"&gt;new DirectoryEntry()&lt;/b&gt; code to include the &lt;i style="mso-bidi-font-style: normal"&gt;root&lt;/i&gt;, &lt;i style="mso-bidi-font-style: normal"&gt;username&lt;/i&gt; and &lt;i style="mso-bidi-font-style: normal"&gt;password&lt;/i&gt; of the context you are trying to connect as (we have reviewed this in previous lessons).&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Finally, please forgive any typo’s – I try hard to make sure there are none.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;I have received a great deal of feedback over the little I have posted so far, and I hope this posting is helpful for some. I apologize again for taking so long to get this series posted.&lt;/p&gt;&lt;img src="http://msftliveblogs.com/mhamilton/aggbug/15.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Michael J. Hamilton, Sr.</dc:creator>
            <guid>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-3.aspx</guid>
            <pubDate>Sat, 10 Nov 2007 14:45:41 GMT</pubDate>
            <wfw:comment>http://msftliveblogs.com/mhamilton/comments/15.aspx</wfw:comment>
            <comments>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-3.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://msftliveblogs.com/mhamilton/comments/commentRss/15.aspx</wfw:commentRss>
            <trackback:ping>http://msftliveblogs.com/mhamilton/services/trackbacks/15.aspx</trackback:ping>
        </item>
        <item>
            <title>.Net Directory Services Programming - C# - Part 2 - DirectoryEntry Binding and AD Properties</title>
            <link>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-2.aspx</link>
            <description>&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;u&gt;.Net Directory Services Programming – C# - Part 2 &lt;/u&gt;      &lt;p&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;u&gt;&lt;/u&gt;      &lt;p&gt;&lt;span style="text-decoration: none"&gt; &lt;/span&gt;&lt;/p&gt;   &lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Topics Covered&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Binding – How to connect to directory services and the flexibility of the bind process.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Properties – Review of the most commonly used AD properties, and a look at a few others.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;u&gt;Binding&lt;/u&gt;&lt;/b&gt;&lt;u&gt; &lt;/u&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;You will remember in Part 1 that we provided a very simple code example of binding to AD and retrieving the object reference for the user object CN=Mike Hamilton. Here I want to review a little more in detail the binding process.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #339966"&gt;Binding The Default Server&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #339966"&gt; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Often called &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;serverless binding, &lt;/i&gt;&lt;/b&gt;or binding to your &lt;b style="mso-bidi-font-weight: normal"&gt;&lt;i style="mso-bidi-font-style: normal"&gt;root context&lt;/i&gt;&lt;/b&gt;, the following shows the simplest of binding calls:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DirectoryEntry newEntry = new DirectoryEntry();&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p style="background: white"&gt;There is one major assumption here: You must be logged into the directory service (or the application you are executing must be) – otherwise the call will fail. This call will return the default server, or default &lt;b style="mso-bidi-font-weight: normal"&gt;root context&lt;/b&gt; – the server that validated your logging onto this network. I will review this in more detail shortly.&lt;/p&gt;  &lt;p style="background: white"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #339966"&gt;Passing The Directory (or ADsPath – we’ll review this in a later Part).&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #339966"&gt; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p style="background: white"&gt;Here we pass the specific server and context that we want to bind to. Borrowing from Part 1 – you’ll remember how we bound to the specific user object.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DirectoryEntry userEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/CN=Mike &lt;city w:st="on"&gt;Hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;=developer,DC=&lt;place w:st="on"&gt;&lt;city w:st="on"&gt;Hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;&lt;/place&gt;=com”); &lt;/b&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;/b&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Here we specify the context of the bind. Note, this can be &lt;i style="mso-bidi-font-style: normal"&gt;any&lt;/i&gt; server within our domain or even another domain within our directory forest.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #339966"&gt;Passing The Path and Credentials to Bind&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #339966"&gt; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Here we want to bind to a specific path, and provide credentials that validate we have the permission to do so. This is important as you delve into security in later Parts.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DirectoryEntry userEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/CN=Mike &lt;city w:st="on"&gt;Hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;=developer,DC=&lt;place w:st="on"&gt;&lt;city w:st="on"&gt;Hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;&lt;/place&gt;=com”, “&amp;lt;adminAccountName&amp;gt;”,”&amp;lt;adminPassword”);&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Here you would replace &lt;i style="mso-bidi-font-style: normal"&gt;adminAccountName&lt;/i&gt; and &lt;i style="mso-bidi-font-style: normal"&gt;adminPassword&lt;/i&gt; with the actual credentials you want to user. Those can be the administrator account or any account that actually has permissions to perform the binding.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #339966"&gt;Passing The Path, Credentials, and Authentication Type&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #339966"&gt; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Not only can we bind with specific credentials, but we can also specify the &lt;i style="mso-bidi-font-style: normal"&gt;authentication type&lt;/i&gt; we wish the directory service to use. For example:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DirectoryEntry userEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/CN=Mike &lt;city w:st="on"&gt;Hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;=developer,DC=&lt;place w:st="on"&gt;&lt;city w:st="on"&gt;Hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;&lt;/place&gt;=com”, “&amp;lt;adminAccountName&amp;gt;”,”&amp;lt;adminPassword”, AuthenticationTypes.Secure); &lt;/b&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;We will review the &lt;i style="mso-bidi-font-style: normal"&gt;AuthenticationTypes&lt;/i&gt; when we review &lt;i style="mso-bidi-font-style: normal"&gt;AuthenticationTypeEnum&lt;/i&gt; in our security review.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;span style="color: #339966"&gt;Passing a Native ADSI Object Reference&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #339966"&gt; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;You will get more into this type of binding when you get into security. For now, I am presenting this for an example/reference for future reviews.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;DirectoryEntry iAdsEntry = new DirectoryEntry(IADSObject);&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;As we move through the different presentations on this topic, we will touch on each of the bindings methods presented, offering examples / benefits of that method.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;u&gt;Properties in AD&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;I clarify here – AD (Active Directory). I should note that LDAP is LDAP across most directory providers. I emphasize AD here because some of the examples I will use are specific to AD insofar as the default behavior of a property or binding context. I will explain those when applicable, and will make a notation in the example conveying that it is an AD specific property or context.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;As mentioned previously, AD (and most directory providers) has a hoard of properties that are available to the developer. Here I want to present some of the most common. What is important to note is the syntax to use when referencing a specific property. (You will remember from Part 1 that property names are spelled out using Camel-Case and single names are in lower-case only.)&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;When a user is initially created, that First Name, Last Name, Account Login Name – ever wondered what these were in AD? There are some givens when interacting with these properties – and I want to point those out first.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The Account Login Name is written to a few AD properties that &lt;i style="mso-bidi-font-style: normal"&gt;cannot&lt;/i&gt; be modified via code. There are some things you can do with an AD user object, but one of the most frustrating is renaming or copying to another directory. You can &lt;i style="mso-bidi-font-style: normal"&gt;move&lt;/i&gt; an object, and of course, delete one – but let’s move forward.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;When the account is first created, the following properties are assigned the names you provide when creating the account (and this is assuming you created the account with a management tool / snap-in that facilitates user management – like AD Users &amp;amp; Computers (dsa.msc)):&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;ul style="margin-top: 0in" type="disc"&gt;   &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l1 level1 lfo1"&gt;First Name = &lt;b style="mso-bidi-font-weight: normal"&gt;givenName&lt;/b&gt; &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l1 level1 lfo1"&gt;Last Name = &lt;b style="mso-bidi-font-weight: normal"&gt;sn&lt;/b&gt; &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l1 level1 lfo1"&gt;Login Account Name = &lt;b style="mso-bidi-font-weight: normal"&gt;sAMAccountName, name, dn&lt;/b&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;&lt;/b&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;If you wanted to retrieve these values using LDAP, and following our example in Part 1, we would do something like the following:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;using System; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;using System.DirectoryServices; &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;namespace DirectoryUtility &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;public class &lt;place w:st="on"&gt;Main&lt;/place&gt;() &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;DirectoryEntry userEntry = new DirectoryEntry(“LDAP://developer.hamilton.com/CN=Mike Hamilton,OU=Developers,OU=Accounts,DC=developer,DC=&lt;place w:st="on"&gt;&lt;city w:st="on"&gt;hamilton&lt;/city&gt;,&lt;state w:st="on"&gt;DC&lt;/state&gt;&lt;/place&gt;=com”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;string loginID = userEntry.Properties[“sAMAccountName”].Value.ToString(); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;string firstName = userEntry.Properties[“givenName”].Value.ToString(); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;string lastName = userEntry.Properties[“sn”].Value.ToString(); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;MessageBox.Show(“Login ID: “+loginID.ToString()+”\r\n Full Name: “+firstName.ToString()+” “+lastName.ToString(),”Results”); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Yes, this is a rough example, and it does not allow for exception handling. The objective was to show you how to reference just these fields.&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;Here I’ll list a few (I say a &lt;i style="mso-bidi-font-style: normal"&gt;few&lt;/i&gt; lightly – there are dozens) properties that you will commonly use or need to use:&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;ul style="margin-top: 0in" type="disc"&gt;   &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;sAMAccountName – user ID of the account created (Note, when programmatically creating/adding users – you have control over this field – but not &lt;i style="mso-bidi-font-style: normal"&gt;after&lt;/i&gt; the object has been added). &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;name – same value as the sAMAccountName property. &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;givenName – First Name of the user. &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;sn – or Sur Name – Last Name of the User &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;displayName – typically, the same as the name, and sAMAccountName &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;userPrincipalName – the same as name, sAMAccountName &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;co – Country &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;mail – single email address value (I’ll demonstrate how we can maintain multiple emails in another Part). &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;telephoneNumber – User’s phone number &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;description – A description of this account &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;userAccountControl – The enumerated property that we’ll use to manage the user’s account – access, password change, locked, and others. &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;wWWHomePage – User’s default homepage –optional. &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;parent – Parent owner object. For example, the name of the OU the user account is in. &lt;/li&gt;    &lt;li class="MsoNormal" style="margin: 0in 0in 0pt; tab-stops: list .5in; mso-list: l0 level1 lfo2"&gt;cn – Cononical – or Common Name – usually the combination of givenName + sn (NOTE: If you have migrated from another system, like NT4 to AD 2000 – this value is the same as the name, sAMAccountName, and displayName – by default, and it cannot be changed) &lt;/li&gt; &lt;/ul&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;How to list and view all properties available with LDAP?&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;The following code snippet shows how to step through the properties associated with a DirectoryEntry object. (NOTE: This code assumes there is a listbox named propertiesListBox on a form that we can add the properties to.)&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;private void PopulateProperties(DirectoryEntry userEntry) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;if (userEntry!=null) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 0.5in"&gt;&lt;span style="color: blue"&gt;{ &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 1in"&gt;&lt;span style="color: blue"&gt;propertiesListBox.Clear(); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 1in"&gt;&lt;span style="color: blue"&gt;foreach (string propertyName in userEntry.Properties.PropertyNames) &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt 1in"&gt;&lt;span style="color: blue"&gt;&lt;span style="mso-tab-count: 1"&gt;            &lt;/span&gt;propertiesListBox.Items.Add(propertyName); &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;}} &lt;/span&gt;    &lt;/p&gt;&lt;p&gt;&lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;    &lt;/p&gt;&lt;p&gt; &lt;/p&gt;   &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;SUMMARY&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;I realize that a lot of this is not meat and potatoes yet, but those Parts are coming. I wanted to take the time to introduce some fundamentals because I realize there are a lot of developers out there that have not been introduced to DirectoryServices, and there is a lot to learn!&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;In our next couple of Parts we are going to look at the DirectorySearcher, the other major class in the DirectoryServices namespace, and then we’re going to look at a few basic examples of user / object management. We will start our own solution that will end up in a complete application that will allow you to connect to a directory service, list accounts and objects in that service, add accounts, add groups, and add other specific objects.&lt;/p&gt;&lt;img src="http://msftliveblogs.com/mhamilton/aggbug/14.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Michael J. Hamilton, Sr.</dc:creator>
            <guid>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-2.aspx</guid>
            <pubDate>Sat, 10 Nov 2007 14:43:45 GMT</pubDate>
            <wfw:comment>http://msftliveblogs.com/mhamilton/comments/14.aspx</wfw:comment>
            <comments>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-2.aspx#feedback</comments>
            <slash:comments>11</slash:comments>
            <wfw:commentRss>http://msftliveblogs.com/mhamilton/comments/commentRss/14.aspx</wfw:commentRss>
            <trackback:ping>http://msftliveblogs.com/mhamilton/services/trackbacks/14.aspx</trackback:ping>
        </item>
        <item>
            <title>.Net Directory Services Programming - C# - Part 1</title>
            <link>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-1.aspx</link>
            <description>&lt;p&gt;As you venture into this aspect of development, you will likely use 1 of 2 assemblies to provide you access to Active Directory (AD) or other directory services providers (DSP's). Microsoft's System.DirectoryServices is the most fundamental - providing core LDAP (lightweight directory access protocol) access to AD and its schema/components. The other is Microsoft's Active Directory Services Interface assembly (ADSI) - the ActiveDs.DLL - which is &lt;strong&gt;not so documented&lt;/strong&gt; but provides a hoard of features for directory services development.&lt;/p&gt;  &lt;p&gt;Here I am going to introduce some basic fundamentals/concepts in an effort to help you understand how these core components interact with AD from your application. In my travels down this path I have found very little in News Groups, on TechNet, or in the development community in general that address the basic fundamentals: Most of my findings are support snippets that assume you understand a lot of core components/constructs already. Most people however, do not.&lt;/p&gt;  &lt;p&gt;As this series continues, we will cover basic AD interfaces that allow your application to interact with AD, users and objects, and update / maintain these objects. We'll gradually venture into more complex topics like security and Access Control Entries (ACE's) and Access Control Lists (ACL's) - which are the underlying interfaces/components that will provide you the ability to deliver directory services applications feature-rich in functionality and utility.&lt;/p&gt;  &lt;p&gt;The only assumptions we'll make here are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;You are familiar with Visual Studio and basic development practices. &lt;/li&gt;    &lt;li&gt;You understand what assemblies / references are in the IDE / application projects. &lt;/li&gt;    &lt;li&gt;You are comfortable with the C# language and .Net in general. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Finally, this is not a definitive guide or approach - it is simply the musings of another Geek in Need - and I hope that conveying some of this knowledge is helpful to other developers.&lt;/p&gt;  &lt;p&gt;So let's begin!!!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;System.DirectoryServices Namespace&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;At the core of this namespace is the primary class &lt;strong&gt;DirectoryEntry&lt;/strong&gt;. There is more here than we will cover for now, but I want to start off simple.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;DirectoryEntry&lt;/strong&gt; is the class you'll use to connect to AD, modify properties, rename or move an AD object, enumerate child objects, create child objects, delete child objects, and collect properties on objects in AD.&lt;/p&gt;  &lt;p&gt;For this review, we'll use an AD server I have that has a DNS of &lt;strong&gt;developer.hamilton.com&lt;/strong&gt;, and it is important to note the domain name components here. &lt;strong&gt;DirectoryEntry&lt;/strong&gt; uses specific &lt;em&gt;naming&lt;/em&gt; identifiers to bind and interact with directory services components. Here are some we'll address initially:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;OU&lt;/strong&gt; - organizationalUnitName, or organizational unit. Note however, how I spelled the initial name - using Camel Case and the fully qualified name. Throughout this series it is important to note this convention as AD uses property names in this fashion - and we will get into that in later parts. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;CN&lt;/strong&gt; - commonName - or canonical name. Examples are Mike Hamilton. In directory services this object is references as &lt;strong&gt;CN=Mike Hamilton&lt;/strong&gt;. We'll cover this more shortly. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;DC&lt;/strong&gt; - domainComponent. Remember the server name above? Fully qualifying a reference to this in a binding to a DirectoryEntry is &lt;strong&gt;DC=developer,DC=hamilton,DC=com&lt;/strong&gt;. I'll cover more on this in a moment too. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Lets say that Mike Hamilton is a user in AD, in the Users OU on the developer.hamilton.com domain. The following is a general reference in how you would qualify this binding in DirectoryEntry:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;LDAP://developer.hamilton.com/CN=Mike Hamilton,OU=Users,DC=developer,DC=hamilton,DC=com&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;When binding with LDAP (or directory services) you'll notice that the connection string (for lack of a better way to describe it) is in a reverse tree order. If you were to browse this entry with Active Directory Users &amp;amp; Computers, you would expand &lt;em&gt;developer.hamilton.com&lt;/em&gt; as the root node, then expand &lt;em&gt;Users&lt;strong&gt;, &lt;/strong&gt;&lt;/em&gt;and finally you would see all of the user objects in that node. If I were to create my domain user accounts in an Accounts OU, and further quantify the user objects by department (like Accounting, Development, etc). I might have something more like:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;developer.hamilton.com&lt;/strong&gt; as the root, with an OU off the root called &lt;strong&gt;Accounts,&lt;/strong&gt; and within &lt;strong&gt;&lt;em&gt;Accounts&lt;/em&gt;&lt;/strong&gt; I would create OU's called &lt;strong&gt;Accounting&lt;/strong&gt;, and another called &lt;strong&gt;Development. &lt;/strong&gt;Now, lets say that Mike Hamilton is in the Development OU. The connection string would look like:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;LDAP://developer.hamilton.com/CN=Mike Hamilton,OU=Development,OU=Accounts,DC=developer,DC=hamilton,DC=com&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now, lets look at a simple C# implementation that will bind and create a DirectoryEntry object reference to this account:&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System.DirectoryServices;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System.Collections;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;namespace DirectoryServicesAtWork&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public class DirectoryUtility&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;{&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;             private DirectoryUtility()&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;             {&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;                   DirectoryEntry userEntry = new DirectoryEntry(”LDAP://developer.hamilton.com/CN=Mike Hamilton,OU=Developers,OU=Accounts,DC=developer,DC=hamilton,DC=com”);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;              }&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;&lt;font color="#000000"&gt;Yes, this is a very simple example, but the above code creates an object reference called &lt;strong&gt;userEntry&lt;/strong&gt; and this object will now allow you to inspect, change, and save changes to properties of the user account &lt;strong&gt;Mike Hamilton&lt;/strong&gt;. &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ACTIVE DIRECTORY PROPERTIES&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;There are a host of properties associated with objects in AD. And if you are working with a Windows 2003 forest, there are even more that were added to 2003. For now, I will review a few fundamental ones and demonstrate interaction with those properties.&lt;/p&gt;  &lt;p&gt;Lets say I want to get the AD user ID, full name, company name, telephone number and email address of the Mike Hamilton object to display on a form? For this example, we will not create a form or the controls for this display. You will notice the textbox control references easily enough. The purpose here is to give you an example of the syntax and how to reference the appropriate properties.&lt;/p&gt;  &lt;p&gt;There are many properties in AD, but we are going to work with only a few for now. As we get into other &lt;em&gt;parts&lt;/em&gt; we will review more properties and how to interact with those.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Get User ID, Full Name, Company Name, Telephone Number, and Email Address.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System.DirectoryServices;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System.Collections;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System.Text;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System.Forms;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;using System.ComponentModel;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;namespace DirecetoryUtility&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;public class frmMain : System.Windows.Forms.Form          // This is the form we'll display our data on...&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;{&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;     // Here we'll skip the normal references to our controls (text boxes, etc.)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;     public frmMain()&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;     {&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;          InitializeComponent();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;          DirectoryEntry userEntry = new DirectoryEntry(”LDAP://developer.hamilton.com/CN=Mike Hamilton,OU=Developers,OU=Accounts,DC=developer,DC=hamilton,DC=com”);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;          if (userEntry!=null)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;          {&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;               txtUserID.Text = userEntry.Properties[”displayName”].Value.ToString();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;               txtFullName.Text = userEntry.Properties[”givenName”].Value.ToString()+” “+userEntry.Properties[”sn”].Value.ToString();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;               if (userEntry.Properties[”companyName”].Value.ToString()!=null)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;                   txtCompanyName.Text = userEntry.Properties[”companyName”].Value.ToString();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;               if (userEntry.Properties[”telephoneNumber”].Value.ToString!=null)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;                    txtPhoneNumber.Text = userEntry.Properties[”telephoneNumber”].Value.ToString();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;               if (userEntry.Properties[”mail”].Value.ToString()!=null)&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;                    txtMail.Text = userEntry.Properties[”mail”].Value.ToString();&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;           }     // End if statement&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;     }     // end frmMain&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;}     // End class&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#000000"&gt;Again, this is a very simple example, but it touches on some very important aspects - Property Names in the directory.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Active Directory properties can be a single value, or a collection (array) of values for the property. For example, the userAccountControl property is an enumeration of values that maintain the account status (i.e. Disabled, User Must Change Password, Password Never Expires, and more). We will get more into properties in Part 2 of this feed.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;SUMMARY&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Here we have only scratched the surface of Directory Services. In the next lesson we will review more in depth the properties of AD DirectoryEntry objects, and how we can manipulate these properties for one purpose or another. We will create a sample application that displays users in a given OU, and allows you to select one from the display and view/modify the properties of that user object.&lt;/p&gt;&lt;img src="http://msftliveblogs.com/mhamilton/aggbug/13.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Michael J. Hamilton, Sr.</dc:creator>
            <guid>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-1.aspx</guid>
            <pubDate>Sat, 10 Nov 2007 14:41:45 GMT</pubDate>
            <wfw:comment>http://msftliveblogs.com/mhamilton/comments/13.aspx</wfw:comment>
            <comments>http://msftliveblogs.com/mhamilton/archive/2007/11/10/.net-directory-services-programming---c---part-1.aspx#feedback</comments>
            <wfw:commentRss>http://msftliveblogs.com/mhamilton/comments/commen