Last post May 17, 2007 03:05 PM by jwmercer
May 17, 2007 02:26 AM|Goodway|LINK
I need to get the canonical name of a user from my asp.net 2.0 web project,
Can anyone help?
May 17, 2007 03:05 PM|jwmercer|LINK
Ok. In order to get anything from the AD you'll need to do the following.
//Make a DirectoryEntry Object.
DirectoryEntry de = new DirectoryEntry(LDAP://your.domain);
//Use this to make a DirectorySearcher Object
DirectorySearch ds = new DirectorySearcher(de);
//Specify the account you want with the .Filter on the ds.
ds.Filter = "sAMAccount = " + username-you-want-the-info-for;
//Add the properties you want to load. The Canonical Name is cn I believe.
//Make a serach result
SearchResult sr = ds.FindOne();
//You'll need to make a string to hold the value and set it to the inumerated value.
string value = sr.Properties["cn"].ToString();
That should about do it.
If you want more info I found that this site:
http://directoryprogramming.net/default.aspx was extremely helpful.