Sign in with
Sign up | Sign in
Your question
Solved

C# help

Last response: in Apps General Discussion
Share
November 30, 2012 6:51:45 PM

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
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.DirectoryServices;
  6. using Microsoft.Office.Interop.Excel;
  7. using System.DirectoryServices.ActiveDirectory;
  8.  
  9.  
  10. namespace EmailListing
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16.  
  17.  
  18.  
  19. DirectoryEntry adFolderObject = new DirectoryEntry("LDAP://OU=PHF Users,DC=phf,DC=inc");
  20. DirectorySearcher adSearchObject = new DirectorySearcher(adFolderObject);
  21. adSearchObject.SearchScope = SearchScope.Subtree;
  22.  
  23.  
  24.  
  25. adSearchObject.Filter = "(&(ObjectClass=user)(!description=Built-in*))";
  26.  
  27.  
  28.  
  29.  
  30. foreach (SearchResult adObject in adSearchObject.FindAll())
  31. {
  32. Console.Write(adObject.Properties["cn"][0]);
  33. Console.Write(".");
  34. Console.WriteLine(adObject.Properties["countryCode"][0]); //Just using countryCode bc I saw it was listed as one of the properties pulled in
  35.  
  36.  
  37.  
  38. }
  39.  
  40. Console.WriteLine();
  41. Console.ReadLine();
  42. }
  43. }
  44. }

More about : question

December 1, 2012 1:49:52 PM

tried that, search the internet everywhere but nothing
m
0
l
Related resources
December 3, 2012 12:20:31 PM

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.
m
0
l
December 3, 2012 1:18:35 PM

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
m
0
l

Best solution

December 3, 2012 2:31:51 PM

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.
Share
December 10, 2012 4:55:33 PM

Best answer selected by laserpp.
m
0
l
December 10, 2012 11:59:46 PM

Was that seriously the answer?
m
0
l
!