1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
try
{
string RNom = row.Cells[1].Value.ToString();
DirectoryEntry ldapConnection = new DirectoryEntry("LDAP://mondomaine", login, mdp);
DirectorySearcher searcher = new DirectorySearcher(ldapConnection);
searcher.Filter = "(sn=" + RNom + ")";
foreach (SearchResult result in searcher.FindAll())
{
// On récupère l'entrée trouvée lors de la recherche
DirectoryEntry DirEntry = result.GetDirectoryEntry();
//On affiche les informations désirées
//Si plusieurs résultats à la recherche ouvre une datagrid pour selectionner l'utilisateur souhaité
if (searcher.FindAll().Count > 1)
{
dataGridView1.Visible = true;
dataGridView1.RowCount = searcher.FindAll().Count;
foreach (DataGridViewRow rows in dataGridView1.Rows)
{
rows.Cells[0].Value = DirEntry.Properties["SAMAccountName"].Value.ToString();
rows.Cells[1].Value = DirEntry.Properties["sn"].Value.ToString();
rows.Cells[2].Value = DirEntry.Properties["givenName"].Value.ToString();
}
}
}
} |
Partager