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 4121550
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:21:57+00:00 2026-05-20T23:21:57+00:00

Az you know every user that is defined in active directory has FirstName,LastName ,UserLoginName(sAMAccountName),Email,….

  • 0

Az you know every user that is defined in active directory has FirstName,LastName ,UserLoginName(sAMAccountName),Email,….
now i have FirstName+LastName of any users on my local network and i want to get UserLoginName of any users from server’s active directory.what can i do??
and here my code::

 DirectoryServices.SearchResult myResult;
 string filterString = string.Empty;
 string EntryString = "LDAP:// MyDomain";
 DirectoryServices.DirectorySearcher myDirectorySearcher = new DirectoryServices.DirectorySearcher(new DirectoryServices.DirectoryEntry(EntryString));
 string tempStr;
 string[] splStr = new string[3];

 filterString = "CN="+FisrtAndLastNameOfUser;
 myDirectorySearcher.Filter = filterString;
 myDirectorySearcher.PropertiesToLoad.Add("UserName");
 myResult = myDirectorySearcher.FindOne();
 splStr = Regex.Split(myResult.Properties("UserName").Item(0).ToString, " ");
 tempStr = splStr(1).ToString + " " + splStr(0).ToString;
 Label1.Text = "Hello " + tempStr;

the outPut of splStr=null;
where is my wrong??
thanks alot.

  • 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-20T23:21:58+00:00Added an answer on May 20, 2026 at 11:21 pm

    If you’re on .NET 3.5 and up, you should check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:

    Managing Directory Security Principals in the .NET Framework 3.5

    Basically, you can define a domain context and easily find users and/or groups in AD:

    // set up domain context for default domain
    PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
    
    // find user by name
    UserPrincipal user = UserPrincipal.FindByIdentity(FirstAndLastNameOfUser);
    
    // if found - access any of its properties
    if(user != null)
    {
       string userLoginName = user.SamAccountName;  // or whatever else you're looking for
    }
    

    The new S.DS.AM makes it really easy to play around with users and groups in AD:

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

Sidebar

Related Questions

I know that in OOP you want every object (from a class) to be
Is there a set of things that every JavaScript programmer should know to be
When i set lower_case_table_names = 1 in mysql i know that it converts every
i know every web-developer hates this topic, but anyway... i found no good solution
I want to know status of every database across a SQL Server farm. I
I need to know how can I get every instruction's duration so I can
every one i m new with ASP .net and I dont know how to
I know there are two posts about this error on SO. Like every google
As you know, the @ characters before a php istruction suppress every eventual warning,
i'd like to update field in my db every tick of timer: I know

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.