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

  • Home
  • SEARCH
  • 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 want to generate random numbers manually. I know that every language have the
You know how Subversion stores a copy of every file it has checked-out in
What are some key UI design tips that every developer should know? While there
Does anyone know of an editor that has the ability to enforce exact line
I know many people who use computers every day, who do not know how
I know how to use tags in subversion. I create a tag every time
Does anyone know why there is no respond_to block for generated edit actions? Every
I will choose Java as an example, most people know it, though every other
In ASP.NET 3.5 (with IIS6), are AppDomains are created for every request? I know
Know of an OCAML/CAML IDE? Especially one that runs on Linux?

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.