c# - Return information about found user Active Directory -


i making active directry managment tool having trouble getting somethings working. while made class want find specific user , return als information(name,fullname,cn,...). can find information when don't know best way return values class.

here code use far:

directorysearcher search = new directorysearcher(ldapconnectie); search.filter = "(cn=" + username + ")"; searchresult result = search.findone();     if (result != null)     {         list<string> listldapfields = new list<string>();         list<object> listldapvalues = new list<object>();         resultpropertycollection fields = result.properties;                  foreach (string ldapfield in fields.propertynames)                 {                     listldapfields.add(ldapfield);                     foreach (object mycollection in fields[ldapfield])                     {                         listldapvalues.add(mycollection);                     }                    }             } 

the program add list. if return cannot search list on "cn" or "name". can find information on index number.

hope can me out.

if you're on .net 3.5 , up, should check out system.directoryservices.accountmanagement (s.ds.am) namespace. read here:

basically, can define domain context , find users and/or groups in ad:

// set domain context using (principalcontext ctx = new principalcontext(contexttype.domain)) {     // find user     userprincipal user = userprincipal.findbyidentity(ctx, username);      if(user != null)     {        // here....        // used attributes available nice, strongly-typed properties        string value = user.givenname;        value = user.surname;        value = user.emailaddress;        value = user.voicetelephonenumber;     } } 

the new s.ds.am makes easy play around users , groups in ad!


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -