Archive for February, 2006

Origami

February 24, 2006

Helping the viral marketing around project origami:

http://www.origamiproject.com/1/

Advertisements

How to retreive ActiveDirectory information for a username

February 9, 2006

Here is a little snippet to read some basic AD user info with C#. The UserADInfo class is a simple three property class.

using System.DirectoryServices;

UserADInfo info = new UserADInfo();
DirectoryEntry entry = new DirectoryEntry("LDAP://mydomain");
// Filter the domain out of the useraccount
String account = userAccount.Replace(@"mydomain\", "");
try {
DirectorySearcher search = new DirectorySearcher(entry);
entry.Username = "mydomain\user"; // someone who has access
entry.Password = "password"

search.Filter = "(SAMAccountName=" + account + ")";
SearchResult result = search.FindOne();
if( result != null ) {
info.UserName = userAccount;
info.FullName = result.Properties["displayname"][0].ToString();
info.Email = result.Properties["mail"][0].ToString();
}
}
catch( Exception ex ) {
string debug = ex.Message;
throw;
}
return info;

Here are some of the AD/LDAP properties listed

http://www.computerperformance.co.uk/Logon/LDAP_attributes_active_directory.htm