Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 321485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:51:00+00:00 2026-05-12T08:51:00+00:00

If I set the .NET DirectoryEntry.Path to something like: LDAP://CN=John Smith,OU=Group Name,DC=example,DC=com Everything works

  • 0

If I set the .NET DirectoryEntry.Path to something like:

LDAP://CN=John Smith,OU=Group Name,DC=example,DC=com

Everything works great, and I get the DirectoryEntry I need. However, I don’t know the user’s true Common Name (CN). I only know their username, “John.Smith”.

So, how can I query the username? I have tried all the following without success:

LDAP://CN=John.Smith,OU=Group Name,DC=example,DC=com
LDAP://sAMAccountName=John.Smith,OU=Group Name,DC=example,DC=com
LDAP://userPrincipalName=John.Smith,OU=Group Name,DC=example,DC=com
LDAP://userPrincipalName=John.Smith@example.com,OU=Group Name,DC=example,DC=com
LDAP://uid=John.Smith,OU=Group Name,DC=example,DC=com
LDAP://o=John.Smith,OU=Group Name,DC=example,DC=com
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:51:01+00:00Added an answer on May 12, 2026 at 8:51 am

    You can’t just query by means of creating an LDAP string – you’ll need to use code for that.

    Something like:

    DirectoryEntry deRoot = new DirectoryEntry("LDAP://yourserver/CN=Users,dc=YourCompany,dc=com");
    
    DirectorySearcher dsFindUser = new DirectorySearcher(deRoot);
    dsFindUser.SearchScope = SearchScope.SubTree;
    
    dsFindUser.PropertiesToLoad.Add("sn"); // surname = last name
    dsFindUser.PropertiesToLoad.Add("givenName"); // first name
    
    dsFindUser.Filter = string.Format("(&(objectCategory=Person)(anr={0}))", yourUserName);
    
    SearchResult rseult = dsFindUser.FindOne();
    
    if(result != null)
    {
       if(result.Properties["sn"] != null)
       {  
          string lastName = result.Properties["sn"][0].ToString();
       }
    
       if(result.Properties["givenName"] != null)
       {  
          string lastName = result.Properties["givenName"][0].ToString();
       }
    }
    

    The full MSDN documentation on the System.DirectoryServices.DirectorySearcher class can be found on MSDN – it has lots of additional properties and settings.

    If you’re on .NET 3.5, things have gotten quite a bit easier with a strongly-typed library of routines for handling users and groups – see this excellent MSDN article on the topic for more info.

    Hope this helps

    Marc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of .NET components that were developed long ago (1.1). I
how to set ASP.NET version for virtual directory using c#.net FROM CODE for all
My company publishes a set of .NET webservices available via SOAP. I need to
I have an existing set of .net libraries that I wish to call from
Is there a way to set a .NET application's TimeZone to a value other
guys! Is there any way to set required .Net Framework in a more universal
I have an ASP.NET website set up, and I'm using Google Analytics for page
Hello I been trying to figure out how to set up ASP.Net forms authentication
In TestDriven.Net I can set the following from the TestDriven.Net Options Pane Run tests
In MVC3 (.Net) it is possible to set a Bind Attribute on a parameter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.