Directory Services |
This topic includes information and a code example that shows how to use a Windows form to enumerate the groups that a user is the member of.
Creating a Windows Form to Display a User's Memberships
[C#]
static void Main()
{
Application.Run(new Form1());
}
private void label1_Click(object sender, System.EventArgs e)
{
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
string strUserADsPath = "LDAP://fabrikam/cn=" +textBox1.Text +",cn=users,dc=fabrikam,dc=com";
DirectoryEntry oUser;
oUser = new DirectoryEntry(strUserADsPath);
listBox1.Items.Add("Groups to which {0} belongs:"+ oUser.Name);
// Invoke IADsUser::Groups method.
object groups = oUser.Invoke("Groups");
foreach ( object group in (IEnumerable)groups)
{
// Get the Directory Entry.
DirectoryEntry groupEntry = new DirectoryEntry(group);
listBox1.Items.Add(groupEntry.Name);
}
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
}