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….
here is the 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 = "(&(objectClass=user))";
SearchResultCollection resultCol = searcher.FindAll();
//Link list for store user names
List<String> User_Names = new List<String>();
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;
Here’s a little something to get you started. It’s a skeleton for a .NET web part class that includes a data-bound
RadioButtonList. To get it deployed to SharePoint, you will also need to roll together a proper .webpart manifest. There are lots of examples of these on the web, and Visual Studio 2010 projects for SharePoint 2010 make it super easy with the Visual Web Part template. (Note that if you are using the Visual Web Part template, then you can write up the web part with an .ascx file like you would any other user control, instead of usingCreateChildControls()as I do below.)Good luck!