Need to edge out the competition for your dream job? Train for certifications today.
Open in new window
DirectoryEntry dir = new DirectoryEntry("LDAP://your_domain_name");
DirectorySearcher search = new DirectorySearcher(dir);
search.Filter = "(&(objectClass=user)(givenname=First_Name))";
SearchResult searchresult = search.FindOne(); // You can also use the FindAll() method for multiple objects.
if (searchresult != null)
foreach(System.Collections.DictionaryEntry direntry in searchresult.Properties)
TextBox1.Text += direntry.Key.ToString() +"\n"; // This will give you all the property names that are set for that particular object
TextBox1.Text += searchresult.GetDirectoryEntry().Properties["sn"].Value.ToString(); // Here displaying the lastname/surname in simple textbox.
Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.
// adUser is administrator user of AD
// adPass is password for same admin user
// conStringPath - LDAP connection string
DirectoryEntry AD = new DirectoryEntry(conStringPath, adUser, adPass, AuthenticationTypes.Secure);
using (DirectorySearcher ds = new DirectorySearcher(AD))
foreach (DirectoryEntry de in AD.Children)
// CN - DisplayName and sAMAccountName - UserLogon
logon = de.Properties["sAMAccountName"].Value.ToString();
name = de.Properties["CN"].Value.ToString().ToUpper();
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.