title: Get User's Manager Details from Active Directory
body: <p>How can I get details like the manager name and email address from the active directory manager associated with a user?</p>
  
  <p>I am able to get all details of users:</p>
  
  <pre><code>ActiveDirectory.SearchUserinAD("ads", "sgupt257");
  
   public static bool SearchUserinAD(string domain, string username)
          {
              using (var domainContext = new PrincipalContext(ContextType.Domain, domain))
              {
                  using (var user = new UserPrincipal(domainContext))
                  {
                      user.SamAccountName = username;
                      using (var pS = new PrincipalSearcher())
                      {
                          pS.QueryFilter = user;
                          var results = pS.FindAll().Cast&lt;UserPrincipal&gt;();
                          {
                              foreach (var item in results)
                              {                                
                                  File.WriteAllText("F:\\webapps\\CIS\\UserInfo.txt", item.DisplayName + item.Name + item.EmailAddress + item.EmployeeId + item.VoiceTelephoneNumber + item.Guid + item.Context.UserName + item.Sid);
                              }
                              if (results != null &amp;&amp; results.Count() &gt; 0)
                              { 
                                  return true;
                              }
                          }
                      }
                  }
              }
              return false;
          }
  </code></pre>
  
  <p>Thanks.</p>