我想使用 LDAP 从目录服务器显示与用户提供的名称匹配的所有名称,并将其绑定到网格视图。我能够完成这项任务,而不仅仅是一个名称,我正在获取其他属性,例如 LDAP://CN=Neha Shetty,OU=Users,OU=MUM,OU=Mumbai,OU=India,OU=APAC,OU=bunt, DC=xxx,DC=com。但我只想要Neha Shetty。这是我的代码
DirectoryEntry de = new DirectoryEntry("ADConnection");
DirectorySearcher deSearch = new DirectorySearcher(de);
//set the search filter
deSearch.SearchRoot = de;
String UserName = txt_To.Text;
// deSearch.Filter = "(&(objectCategory=user)(GivenName=*" + UserName + "*))";
deSearch = new DirectorySearcher("(&(objectCategory=user)(Name=*" + UserName + "*))");
//deSearch.SearchScope = SearchScope.Subtree;
string[] arrPropertiesToLoad = { "Surname" };
deSearch.PropertiesToLoad.AddRange(arrPropertiesToLoad);
// SearchResultCollection sResultColl = deSearch.FindAll();
SearchResultCollection sResultColl;
sResultColl = deSearch.FindAll();
Gridview1.DataSource = sResultColl;
Gridview1.DataBind();