Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to get all the node attributes in Active Directory in LDAP C#?.
Currently I am getting only the root domain attributes with below code.


Code as follows:
C#
DirectoryEntry entry = new DirectoryEntry("LDAP://" + ldapserver + ":" + ldapport + "/" + ldapbasedn, ldapuser, ldappassword, AuthenticationTypes.None);
               //Open Active Directory with LDAP Connection String/Path with Credentials
               //DirectoryEntry entry = new DirectoryEntry("LDAP://" + ldapserver + "/" + ldapbasedn, ldapuser, ldappassword, AuthenticationTypes.None);

               DirectorySearcher ds = new DirectorySearcher(entry);
               //ds.Filter=("(objectClass=*)");
               //ds.SearchScope = SearchScope.Subtree;
               //ds.Filter = "(cn=orgPerson)"; //Search how you want.  Google "LDAP Filter" for more.
              // ds.Filter = "(&(objectClass=top)(l=" + CertificateAttributeType + "))";
               //ds.Filter = "(uid=personUID)";
               //Fetch all Attributes in the LDAP Server
               SearchResultCollection result = ds.FindAll();
Posted
Updated 29-Oct-15 23:07pm
v2
Comments
phil.o 30-Oct-15 5:41am    
Please show the code where you are iterating over your SearchResultCollection.
Korathu123 30-Oct-15 6:02am    
I want to fetch all user certificate values in all the nodes if any
foreach (SearchResult r in result)
{
string CertificateAttributeType="userCertificate:binary";
if (r.Properties.Contains(CertificateAttributeType))
{
Common.WriteEFTSLog("EFTS:Has "+CertificateAttributeType+" ");
if (r.Properties[CertificateAttributeType].Count > 0)
{
Common.WriteEFTSLog("EFTS:Certificate Exists there");
for (int m = 0; m < r.Properties[CertificateAttributeType].Count; m++)
{
Byte[] b = (Byte[])r.Properties[CertificateAttributeType][m];
//Convert byte data of User Certificate Fetched to the Certificate file and add it to the Certificate Store

//Set a certificate file Path configured in App.config to which fetched Byte array is passed
string cerFilePath = ConfigurationSettings.AppSettings["CertFilePath"].ToString();
//Create the Certificate File from Byte Array data
bool CertFileCreation = ByteArrayToFile(cerFilePath, b);
if (CertFileCreation == true)
{
Common.WriteEFTSLog("EFTS:Certificate File Created from Byte Array");
// Convert the Filename to an X509 Certificate
X509Certificate2 cert = new X509Certificate2(cerFilePath);
// Get the server certificate store and pass to Personal Certificate Store(Check with Certmgr.msc in Run)
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
//Add the Certificate File to Windows Cetificate Store
store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(cerFilePath)));
store.Close();
Common.WriteEFTSLog("EFTS:Certificate File Added to the Store");

}
}

}
else
{
Common.WriteEFTSLog("EFTS:No Certificate Exists");
}

}
phil.o 30-Oct-15 6:04am    
Comments are not meant to hold code block. Please delete your comment and qualify your question with relevant code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900