Sharepoint的CAML查询中的日期时间比较

Gar*_*ien 12 c# sharepoint web-parts caml

我正在尝试从sharepoint列表中获取某些项目,具体取决于自定义列中的日期.

我已经建立了我与U2U CAML查询生成器,而这工作,但是当我把它放在我自己的代码在我的WebPart,它总是返回我的所有项目OD列表.

这是我的代码:

DateTime startDate = new DateTime(Int32.Parse(year), 1, 1);
            DateTime endDate = new DateTime(Int32.Parse(year), 12, 31);
            SPQuery q = new SPQuery();
            q.Query = "<Query><Where><And><Geq><FieldRef Name='Publicate Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(startDate) + "</Value></Geq><Leq><FieldRef Name='Publicate_x0020_Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(endDate) + "</Value></Leq></And></Where></Query>";

            SPListItemCollection allItem = library.GetItems(q);
Run Code Online (Sandbox Code Playgroud)

Tun*_*dey 11

你不需要<Query>标签.这就是你没有执行查询的原因.

  • 我总是把这些错误归咎于星期一这个错误. (5认同)