C# help

Alright had another thread but closed it to make a fresh one.

I have multiple problems but going to take them on 1 at a time. First problem I am accessing my Active Directory and producing all the CN (user names). I want to also produce their email addresses(MAIL). For some reason when pulling in the data from the AD it is only bringing in 32 fields out of the like 60-70 each user has(and of course MAIL isn't one of them). Does anyone know why it isn't pulling in all the properties?

Here's the code

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;
using Microsoft.Office.Interop.Excel;
using System.DirectoryServices.ActiveDirectory; 

namespace EmailListing
    class Program
        static void Main(string[] args)
            DirectoryEntry adFolderObject = new DirectoryEntry("LDAP://OU=PHF Users,DC=phf,DC=inc");
            DirectorySearcher adSearchObject = new DirectorySearcher(adFolderObject);
            adSearchObject.SearchScope = SearchScope.Subtree;

            adSearchObject.Filter = "(&(ObjectClass=user)(!description=Built-in*))";


            foreach (SearchResult adObject in adSearchObject.FindAll())
                Console.WriteLine(adObject.Properties["countryCode"][0]); //Just using countryCode bc I saw it was listed as one of the properties pulled in

7 answers Last reply Best Answer
More about help
  1. I'm not particularly familiar with the AD-related classes, but you may need to add "mail" to adSearchObject.PropertiesToLoad (see
  2. tried that, search the internet everywhere but nothing
  3. Have you tried looking to see if 32 fields is some sort of built-in limitation? Perhaps you need to trim some off in order to bring in new ones. I just ask as 32 is a nice 2^x (5 in this case) number in classic computer tradition and could see some enterprising developer thinking that's *got* to be more than enough. This is well within the bounds of even a 16 bit integer but it's an interesting anecdote to me.
  4. Interesting, didn't think about that, I will look into that, the thing is the 32 fields are like spread all over the users account, it isnt like the first 32 fields which I would think is wierd if it did limit to only 32 fields. If that was the case wouldn't it just pick the first 32 fields
  5. Best answer
    I have no idea. As I said this is beyond my expertise. I just thought the number of 32 was interesting considering there are more than double that available and that nothing "just happens" in the world of coding. Things only happen when code says to do so.
  6. Best answer selected by laserpp.
  7. Was that seriously the answer?
Ask a new question

Read More

Programming Active Directory Apps