troubleshooting Question

Ldapv3 not returning fields which are empty in AD profile

Avatar of Mahesh Yadav
Mahesh YadavFlag for India asked on
C#ASP.NETActive Directory
3 Comments1 Solution580 ViewsLast Modified:
I am trying to run the following code it is working fine but there is an issue.
the issue is it is only those fields which has a value.
All those fields which are empty are not coming.

for example, if in my user in AD has a value in email field then it is coming otherwise not.
I am also giving the code, could any one help me out here.

I am using LDapv3 here

here is the code.

  public static void Main(string[] args)

                //LdapDirectoryIdentifier ldapDir = new LdapDirectoryIdentifier("CBMCC-A8-HPC06", 389);

                LdapDirectoryIdentifier ldapDir = new LdapDirectoryIdentifier("", 389);
                LdapConnection ldapConn = new LdapConnection(ldapDir);
                //You may need to try different types of Authentication depending on your setup
                ldapConn.AuthType = AuthType.Basic;
                //Update the next line to include the Fully Qualified LDAP name
                // of the user along with that user's password
                System.Net.NetworkCredential myCredentials =
                    new System.Net.NetworkCredential("jet\\administrator", "1nT1meTec");
                ldapConn.SessionOptions.ProtocolVersion = 3;
                //This is the actual Connection establishment here

                Console.WriteLine("LdapConnection is created successfully.");


                //SearchRequest findme = new SearchRequest("dc=jet,dc=in", "(objectClass=printQueue)", System.DirectoryServices.Protocols.SearchScope.Subtree,"*", "+");

                SearchRequest findme = new SearchRequest("CN=Users;dc=Jet,dc=in", "(objectClass=user)",
                    System.DirectoryServices.Protocols.SearchScope.Subtree, "*", "+");

                //findme.DistinguishedName = "dc=jet,dc=in"; //Find all People in this ou
                //findme.Filter = "(objectClass=user)"; //The type of entry we are looking for
                //findme.Scope = System.DirectoryServices.Protocols.SearchScope.Subtree; //We want all
                //entries below this ou

                SearchResponse results = (SearchResponse)ldapConn.SendRequest(findme); //Run the query

                //and get results
                SearchResultEntryCollection entries = results.Entries;
                List<string> lstAtributes = new List<string>();
                if (entries != null && entries.Count > 0) {
                    SearchResultEntry entry = entries[0];
                    IDictionaryEnumerator attributes = entry.Attributes.GetEnumerator();
                    while (attributes.MoveNext()) {
                for (int ii = 0; ii < entries.Count; ii++)//Iterate through the results
                    SearchResultEntry entry = entries[ii];
                    IDictionaryEnumerator attribEnum = entry.Attributes.GetEnumerator();
                    while (attribEnum.MoveNext())//Iterate through the result attributes
                        //Attributes have one or more values so we iterate through all the values
                        //for each attribute
                        DirectoryAttribute subAttrib = (DirectoryAttribute)attribEnum.Value;
                        for (int ic = 0; ic < subAttrib.Count; ic++)
                            //Attribute Name below
                            Console.Write(subAttrib.Name + ": ");
                            //Attribute Sub Value below

            catch (Exception e)
                Console.WriteLine("\r\nUnexpected exception occured:\r\n\t" + e.GetType() + ":" + e.Message);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros