If you are on .NET 3.5, or could upgrade to it - the LDAP stuff has been vastly improved with the introduction of the System.DirectoryServices.AccountManagement
namespace.
It contains among other things classes like UserPrincipal
, which offers most of the commonly used LDAP attributes as properties. Using the PrincipalSearcher
and QBE (Query-by-example), you could very easily find those users (or other objects) you're interested in and binding them to the ASP.NET grid view.
To learn more about the new .NET 3.5 stuff, read this excellent article at MSDN Magazine:
Managing Directory Security Principals in the .NET Framework 3.5
Update: Using the .NET 3.5 interface, you can write code something like this:
// define the content - domain name (second param) must be NetBIOS-style,
// third parameter is the container where to create the context for
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "ITLAB", "OU=UsersStudents,DC=dc,DC=itlab,DC=edu");
// define your "prototype" for the searcher - here: you want to search for
// users which have the .Enabled property set to true; you could define additional
// requirements here
UserPrincipal qbePrototype = new UserPrincipal(ctx);
qbePrototype.Enabled = true;
// create PrincipalSearcher based on that QBE prototype
PrincipalSearcher ps = new PrincipalSearcher(qbePrototype);
// find all matching Principals - in your case, those will be of type UserPrincipal
PrincipalSearchResult<Principal> results = ps.FindAll();
Now you should be able to bind the results
directly to a DataGridView
or something, and pick out those properties for your columns that you're looking for:
- First Name = UserPrincipal.GivenName
- Last Name = UserPrincipal.Surname
- Pre-Windows 2000 Logon Name = UserPrincipal.SamAccountName
- Name = Name
- Type = ?? What you do mean here??