SharePoint 列表视图 - 查询字符串中的日期时间

发布于 2024-08-09 18:51:59 字数 1196 浏览 1 评论 0原文

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

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

         <Where>
            <And>
              <Geq>
                <FieldRef Name="Event_x0020_Start_x0020_Date" />
                <Value Type=”DateTime”>2009-10-10T10:00:00Z</Value>
              </Geq>
              <Leq>
                <FieldRef Name="Event_x0020_Start_x0020_Date" />
                <Value Type=”DateTime”>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),查询工作正常。

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

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

谢谢!

I am writing a view for a list of events in SharePoint (Schema.xml) and I want to filter the results according to a DateTime (i.e. only display the events that start between 2 dates)

Normally I would use a CAML Query like this one for example :

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

However, in this case, the dates that I want to compare to are not available directly in a field, I have to fetch them from the Query String.

I tried using

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

where Start and End are 2 dates in the Query String (I tried every date format, with and without the Type="DateTime") but I always get empty results. The query works fine when I hardcode my dates (with say 2009-10-10T10:00:00Z).

I have control over what I send in the Query String so I can change it if there is another way.

So is there a way to get a DateTime format in the query string? If not, do I have other options?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我不是你的备胎 2024-08-16 18:51:59

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

即:

<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”>{StartDateParameter}</Value>
    </Geq>
    <Leq>
      <FieldRef Name="Event_x0020_Start_x0020_Date" />
      <Value Type=”DateTime”>{EndDateParameter}</Value>
    </Leq>
  </And>
</Where>

Have you tried adding a custom page and then adding a DataFormWebPart (DFWP) to it? That in turn would allow you to shape your CAMl query in the SelectCommand of the SPDatasource used by the DFWP, using actual ASP.NET Calendar Controls to be used as parameters, specified in the SPDataSource's parameters. Use Control(ID, PROPERTYTOUSEINCAML) in the parameterbindings of the spdatasource.

i.e.:

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

then have the SelectCommand's CAML be something like:

<Where>
  <And>
    <Geq>
      <FieldRef Name="Event_x0020_Start_x0020_Date" />
      <Value Type=”DateTime”>{StartDateParameter}</Value>
    </Geq>
    <Leq>
      <FieldRef Name="Event_x0020_Start_x0020_Date" />
      <Value Type=”DateTime”>{EndDateParameter}</Value>
    </Leq>
  </And>
</Where>
自此以后,行同陌路 2024-08-16 18:51:59

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

list.Fields["Display Name"].InternalName  

,使用 SPUtility 的日期实用程序

Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(System.DateTime.Now)

First off, a common mistake in CAML is to not use the internal name of a field... try using the

list.Fields["Display Name"].InternalName  

Secondly, use the SPUtility's date utility

Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(System.DateTime.Now)
腻橙味 2024-08-16 18:51:59

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

The correct date format in querystring is yyyy-mm-dd please refer this post

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文