title: How to get user Names of domain in Sharepoint web part?
body: <p>I want to get user names in active directory by using sharepoint webpart.
  any way a i can get usernames by using  ASP. net but i cant convert that code in to sharepoint web part....</p>
  
  <p>here is the code .........</p>
  
  <pre><code>          using System;
            using System.Collections.Generic;
            using System.Linq;
            using System.Web;
            using System.Web.UI;
            using System.Web.UI.WebControls;
            using System.DirectoryServices;
            using System.Data;
  
  
          string domain = "LDAP://serverName";
          DirectoryEntry entry = new DirectoryEntry(domain);
  
          DirectorySearcher searcher = new DirectorySearcher(entry);
  
          searcher.Filter = "(&amp;(objectClass=user))";
  
          SearchResultCollection resultCol = searcher.FindAll();
  
          //Link list for store user names 
          List&lt;String&gt; User_Names = new List&lt;String&gt;();
  
          int count = 0;
  
          foreach (SearchResult result in resultCol)
          {
              User_Names.Add(result.Properties["CN"][0].ToString());
              count = count + 1;
          }
  
          //can print all user names by using for loop or while loop 
  
          Label2.Text = RadioButtonList1.SelectedItem.Text;
  </code></pre>