我正在尝试从共享点列表中获取一些项目,具体取决于自定义列中的日期。
我已经使用 U2U Caml Builder 创建了我的查询,这很有效,但是当我将它放入我自己的 Web 部件代码中时,它总是返回列表中的所有项目。
这是我的代码:
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);
最佳答案
您不需要 <Query>
标签。这就是您查询未被执行的原因。
关于c# - Sharepoint 的 CAML 查询中的日期时间比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4648517/