1

我正在为 SharePoint (Schema.xml) 中的事件列表编写一个视图,并且我想根据 DateTime 过滤结果(即仅显示在 2 个日期之间开始的事件)

通常我会使用像这样的 CAML 查询,例如:

         <Where>
            <And>
              <Geq>
                <FieldRef Name="Event_x0020_Start_x0020_Date" />
                <Value Type=”DateTime”&gt;2009-10-10T10:00:00Z</Value>
              </Geq>
              <Leq>
                <FieldRef Name="Event_x0020_Start_x0020_Date" />
                <Value Type=”DateTime”&gt;2009-11-10T10:00:00Z</Value>
              </Leq>
            </And>
          </Where>

但是,在这种情况下,我想比较的日期不能直接在字段中使用,我必须从查询字符串中获取它们。

我尝试使用

        <Value Type="DateTime">
          <GetVar Scope="Request" Name="Start" />
        </Value>
        <Value Type="DateTime">
          <GetVar Scope="Request" Name="End" />
        </Value>

其中 Start 和 End 是查询字符串中的 2 个日期(我尝试了每种日期格式,有无 Type="DateTime"),但我总是得到空结果。当我硬编码我的日期(比如 2009-10-10T10:00:00Z)时,查询工作正常。

我可以控制我在查询字符串中发送的内容,因此如果有其他方法,我可以更改它。

那么有没有办法在查询字符串中获取 DateTime 格式?如果没有,我还有其他选择吗?

谢谢!

4

3 回答 3

3

您是否尝试过添加自定义页面,然后向其中添加 DataFormWebPart (DFWP)?这反过来将允许您在 DFWP 使用的 SPDatasource 的 SelectCommand 中塑造您的 CAMl 查询,使用实际的 ASP.NET 日历控件作为参数,在 SPDataSource 的参数中指定。在 spdatasource 的参数绑定中使用 Control(ID, PROPERTYTOUSEINCAML)。

IE:

<ParameterBinding Name="StartDate" Location="Control(calStart, SelectedDate)" DefaultValue="01-01-2009"/>
<ParameterBinding Name="EndDate" Location="Control(calEnd, SelectedDate)" DefaultValue="01-01-2009"/>

然后让 SelectCommand 的 CAML 类似于:

<Where>
  <And>
    <Geq>
      <FieldRef Name="Event_x0020_Start_x0020_Date" />
      <Value Type=”DateTime”&gt;{StartDateParameter}</Value>
    </Geq>
    <Leq>
      <FieldRef Name="Event_x0020_Start_x0020_Date" />
      <Value Type=”DateTime”&gt;{EndDateParameter}</Value>
    </Leq>
  </And>
</Where>
于 2009-11-01T05:42:42.510 回答
0

首先,CAML 中的一个常见错误是不使用字段的内部名称...尝试使用

list.Fields["Display Name"].InternalName  

其次,使用 SPUtility 的日期实用程序

Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(System.DateTime.Now)
于 2009-11-01T02:01:24.830 回答
-1

查询字符串中正确的日期格式是 yyyy-mm-dd 请参考这篇文章

于 2015-03-24T14:33:14.560 回答