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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:48:01+00:00 2026-06-09T14:48:01+00:00

I am doing some querying in active directory at the moment, our database user

  • 0

I am doing some querying in active directory at the moment, our database user id matches that of the active directory user id.

I am passing the user id along with the domain and the path to get what I need. My endeavour is to get the email address of the manager from the passed user id. What I am returning when I get the manager property is the distinguished name.

Finding a user's manager record in Active Directory

This above post is my exact problem, but it’s an old post and there are no further descriptives on how to move forward and the OP knew what to do next with the distinguished name. Truth is, I don’t.

So my question is, how to I get the email address property from the distinguished name which I have thus far stored as a string with a prefix of LDAP:// + “MyDistinguishedName”?

 public string GetManagerEmail(string ActiveDirectoryPath, string ActiveDirectoryDomain, bool email)
    {

        DirectoryEntry entry = new DirectoryEntry(ActiveDirectoryPath);

        try
        {
            DirectorySearcher search = new DirectorySearcher(entry);

            search.Filter = "(SAMAccountName=" + workerID + ")";
            search.PropertiesToLoad.Add("cn");
            search.PropertiesToLoad.Add("givenname");  //firstname
            search.PropertiesToLoad.Add("sn");//surname
            search.PropertiesToLoad.Add("manager");
            search.PropertiesToLoad.Add("email");
            SearchResult result = search.FindOne();

            if (null == result)
            {
                return workerID;
            }
            if (email)
            {
                return (string)result.Properties["email"][0];
            }
            else
            {
                return (string)result.Properties["manager"][0];
                //return (string)result.Properties["manager"].IndexOf[];
            }
        }
        catch (Exception ex)
        {
            throw new Exception("Error. " + ex.Message);

        }
        finally
        {
            entry.Close();
        }
    }

Above is the method I use to get the data I need. Any input or improvements would be appreciated.

Thanks

THIS IS MY SOLUTION FOR THOSE THAT MAY BE INTERESTED

            string domainAndUsername = ActiveDirectoryDomain + @"\" + workerID;
        DirectoryEntry manager = new DirectoryEntry(ActiveDirectoryPath);

        try
        {
            if (manager != null)
            {
                // get e-mail of manager 
                if (manager.Properties["mail"] != null && manager.Properties["mail"].Count > 0)
                {
                    string managersEMail = manager.Properties["mail"].Value.ToString();
                    return managersEMail;
                }
            }

            //No email available, use contract manager
            return string.Empty;

        }
        catch (Exception ex)
        {
            throw new Exception("Error. " + ex.Message);

        }
        finally
        {
            manager.Close();
        }
  • 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-06-09T14:48:03+00:00Added an answer on June 9, 2026 at 2:48 pm

    There is no “magic” shortcut to getting the e-mail of a manager.

    Once you’ve retrieved the DN (distinguished name) of your manager (in a string variable called managerDN), you need to again bind to Active Directory by creating another instance of a DirectoryEntry to grab the manager’s user info.

    Try something like this:

     .....(your other code up here)......
     else
     {
         string managerDN = result.Properties["manager"][0].ToString();
    
         // fully-qualified DN for manager
         string managerFQDN = "LDAP://" + managerDN;
    
         DirectoryEntry manager = new DirectoryEntry(managerFQDN);
    
         if(manager != null)
         {
            // get e-mail of manager
            if(manager.Properties["mail"] != null && 
               manager.Properties["mail"].Count > 0)
            {
               string managersEMail = manager.Properties["mail"].Value.ToString();
               return managersEMail;
            }
         }
    
         // we couldn't retrieve the manager's e-mail  
         return string.Empty;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While doing some refactoring I've found that I'm quite often using a pair or
Been doing some playing call my service which is on a different domain using
I'm doing some queries in Python on a large database to get some stats
I am doing some basic SQL Lite database work via a C# application. I
I am trying to index data from database. I am doing that successfully. But
I have a C# application that scans a directory and gathers some information. I
Doing some profiling (mem & speed) I've been stomped by the fact that win7
I am using SQL Server 2008. I have some dates in my database that
I was doing some querying today in T-SQL, SQL-Server-2008 and stumbled upon something weird
Doing some jquery animation. I have certain divs set up with an attribute of

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.