this code will return you current ldap user or ldap users with groups
// get current ad user _username = System.Security.Principal. WindowsIdentity.GetCurrent().Name .Split( new string [] {"\\"}, StringSplitOptions.None)[1]; // get all users with groups Dictionary<string ,string[]> userGroups; private void uxBtnGetir_Click(object sender, EventArgs e) { IEnumerable<User > users = GetADUsers(string.IsNullOrEmpty(uxUsername.Text)); uxLvKullanicilar.Items.Clear(); foreach (User _user in users) { uxLvKullanicilar.Items.Add( new Infragistics.Win.UltraWinListView.UltraListViewItem ( _user.sAMAccountName, new object [] { _user.Name, _user.mail })); userGroups.Add(_user.sAMAccountName, _user.Groups); } } static DirectoryEntry ROOT = new DirectoryEntry("LDAP://Company" ); private static string username; private static IEnumerable< User> GetADUsers(bool allusers=false) { IEnumerable<User > users; var usersDS = new DirectorySource< User>(ROOT, SearchScope .Subtree); string usernameq = allusers ? "*" : "*" username "*"; users = from usr in usersDS where usr.Name == usernameq select usr; users = users.OrderBy(user => user.Name).ToList(); return users; }
Comments