title: How to pull a user's city location from Active Directory in C# .net
body: <p>I'd like to do a LDAP query against AD to pull a user's location (city). This is what I've put together:</p>
  
  <pre><code>    public static string GetUserLocation(string userName)
      {            
          string userLoc = "";
  
          DirectoryEntry entry = new DirectoryEntry("LDAP://FTLAD04.corp.myDomain.com");
          DirectorySearcher dSearch = new DirectorySearcher(entry);
  
          dSearch.Filter = "(&amp;(objectClass=user)(l=" + userName + "))";
          dSearch.PropertiesToLoad.Add("city");
  
          SearchResult result = dSearch.FindOne();
          userLoc = result.ToString();
  
          entry.Close();
  
          return userLoc;
      }
  </code></pre>
  
  <p>My SearchResult keeps coming back null, can anyone help point me in the right direction? Thank you!</p>