2012-09-14 35 views
0

我正在嘗試獲取當週所有的生日和週年紀念日。我正在使用Directory SearcherLDAP。我是新來LDAP,我使用下面的代碼:DirectorySearcher.Filter查詢活動目錄以返回當前周的即將發生的事件

  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; 

回答

1

存儲在用戶的描述屬性在你的事件?

對於屬性值的外觀沒有太多的細節。

您正在嘗試向用戶C#我沒有獲得,而是從一個LDAP查詢,這個工程: (&(objectClass的=用戶)(說明= 9月15日*))

-Jim

相關問題