/ Published in: C#
This is very useful if you need to populate a dropdown.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Get all users from an Active Directory distribution group public SortedList GetUsersInGroup(string domain, string group) { string sam = ""; string fname = ""; string lname = ""; string active = ""; ds.Filter = "(memberOf=CN=" + group + ",OU=Distribution Groups,DC=" + domain + ",DC=com)"; ds.PropertiesToLoad.Add("givenname"); ds.PropertiesToLoad.Add("samaccountname"); ds.PropertiesToLoad.Add("sn"); ds.PropertiesToLoad.Add("useraccountcontrol"); foreach (SearchResult sr in ds.FindAll()) { try { sam = sr.Properties["samaccountname"][0].ToString(); fname = sr.Properties["givenname"][0].ToString(); lname = sr.Properties["sn"][0].ToString(); active = sr.Properties["useraccountcontrol"][0].ToString(); } catch (Exception e) { } // don't grab disabled users if (active.ToString() != "514") { groupMemebers.Add(sam.ToString(), (fname.ToString() + " " + lname.ToString())); } } return groupMemebers; }