使用CAML查询日期字段

时间:2013-08-02 03:31:38

标签: sharepoint object model client caml

我正在尝试针对共享点列表运行查询(使用客户端对象模型),查找与日期字段匹配的项目。

我的查询是:                                                                                2012-07-24T02:50:28                                       1             

我知道列表中有一个项目,其中EmDateSent字段的值为2012-07-24T02:50:28但是当我运行它时,我得到0行。

花了几个小时研究和试验我发现我使用的日期格式是有效的 - 或者我认为。现在似乎没有。

我的代码如下。

任何人都可以提出我可以尝试的其他内容吗?

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = String.Format(
    @"<View>
         <Query>
             <Where>
                <Eq>
                   <FieldRef Name='{0}'/>
                      <Value Type='DateTime' IncludeTimeValue='True'>{1}</Value>
                </Eq>
             </Where>
         </Query>
      </View>", EMAIL_FIELD_DATE_SENT, details.DateSent.HasValue ?   details.DateSent.Value.ToString("yyyy-MM-ddTHH:mm:ss") : "");


ListItemCollection listItems = upLoadList.GetItems(camlQuery);

_context.Load(listItems);
_context.ExecuteQuery();

if (listItems.Count > 0)  // At this point I expect listItems.Count to be 1, but it is   0
{
    ....

1 个答案:

答案 0 :(得分:0)

您的示例看起来正确,并且在时间戳中使用“T”没有问题。但是,根据我的发现,像您这样的大多数示例都使用SPQuery class而不是CamlQuery class。我相信这会引起你的问题。

相关问题