我正在尝试获取所有属于本周的生日和纪念日。我正在使用Directory Searcher
和LDAP
。我是新手LDAP
,我正在使用以下代码:
string _path = "LDAP:";
System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(_path);
DirectorySearcher ds = new DirectorySearcher(entry);
string month = DateTime.Now.Month.ToString();
string day = DateTime.Today.Day + numDays.ToString();
ds.Filter = "(&(objectClass=user)(description=" + month + "\\" + day +"))";
SortOption option = new SortOption("description", System.DirectoryServices.SortDirection.Ascending);
ds.Sort = option;
DataSet dSet = new DataSet();
DataTable dTable = new DataTable("Events");
dTable.Columns.Add("birthday");
foreach (System.DirectoryServices.SearchResult resEvent in ds.FindAll())
{
System.DirectoryServices.DirectoryEntry de1 = resEvent.GetDirectoryEntry();
DataRow dRow = dTable.NewRow();
if (de1.Properties["description"].Value != null)
{
dRow["birthday"] = de1.Properties["description"].Value.ToString();
dTable.Rows.Add(dRow);
}
}
dSet.Tables.Add(dTable);
return dSet;