c# - Loop LDAP memberOf as return to show all for single user -
pretty new using ldap, , c# in general, , did more few searches, of attempted fixes have lead nowhere.
i pulling information ldap. works, except can pull memberof information if explicit in array number want. attempts use foreach
, or for
statement have lead nowhere. know missing simple, figured should ask.
public static string findother(string useraccount) { directoryentry entry = getdirectoryentry(); directorysearcher search = new directorysearcher(entry); try { search.filter = "(samaccountname=" + account + ")"; search.propertiestoload.add("distinguishedname"); search.propertiestoload.add("displayname"); search.propertiestoload.add("mail"); search.propertiestoload.add("cn"); search.propertiestoload.add("title"); search.propertiestoload.add("sn"); search.propertiestoload.add("givenname"); search.propertiestoload.add("telephonenumber"); search.propertiestoload.add("memberof"); searchresult result = search.findone(); if (result != null) { return "results " + useraccount + "\n" + " distinguishedname..: " + result.properties["distinguishedname"][0].tostring() + "\n" + " displayname........: " + result.properties["displayname"][0].tostring() + "\n" + " email..............: " + result.properties["mail"][0].tostring() + "\n" + " common name........: " + result.properties["cn"][0].tostring() + "\n" + " title..............: " + result.properties["title"][0].tostring() + "\n" + " last name..........: " + result.properties["sn"][0].tostring() + "\n" + " first name.........: " + result.properties["givenname"][0].tostring() + "\n" + " telephone..........: " + result.properties["telephonenumber"][0].tostring() + "\n" + " member of..........: " + result.properties["memberof"][0].tostring() + "\n" + " member of..........: " + result.properties["memberof"][1].tostring() + "\n" + "end transmission" + "\n"; } else { return "object not found... user id: " + account; } } catch (exception ex) { return "big ol error: " + ex.message + " user id: " + account; } }
thank provide.
you can enumerate through propertycollection way:
string ret = string.empty; ... foreach(object memberof in result.properties["memberof"]) { ret += " member of..........: " + memberof.tostring() + "\n"; }
Comments
Post a Comment