【问题标题】:Get newest ListItems from a List从列表中获取最新的 ListItems
【发布时间】:2017-12-20 09:07:59
【问题描述】:

有没有办法从 Microsoft Graph 获取 n 个最新列表项或一年内创建的项?

到目前为止我已经尝试过:

// .Filter("CreatedDateTime gt 2016-12-18T14:13:30Z")
var news = client.Sites[Root]
    .SiteWithPath(path)
    .Lists[newsListId]
    .Items
    .Request()
    .Filter("CreatedDateTime gt 2016-12-18T14:13:30Z")
    .GetAsync()
    .Result;
// => The request is malformed or incorrect.

// .OrderBy("CreatedDateTime desc")
var news = client.Sites[Root]
    .SiteWithPath(path)
    .Lists[newsListId]
    .Items
    .Request()
    .OrderBy("CreatedDateTime desc")
    .GetAsync()
    .Result;
// => returns data but not in the requested order

//.Filter("year(CreatedDateTime) eq 2017")
var news = client.Sites[Root].SiteWithPath(path)
    .Lists[newsListId]
    .Items
    .Request()
    .Filter("year(CreatedDateTime) eq 2017")
    .GetAsync()
    .Result;
// => ServiceException: Code: itemNotFound
//    Message: The resource could not be found.

【问题讨论】:

    标签: sharepoint microsoft-graph-api


    【解决方案1】:

    将结果限制为 N 个结果的查询参数是 $top。见https://developer.microsoft.com/en-us/graph/docs/concepts/query_parameters

    我不熟悉你使用的 SDK,所以我不能给你确切的代码,但是 URL 形式的示例是

    https://graph.microsoft.com/v1.0/sites/root/lists?$top=4
    

    也许你可以试试:

    .Top(N)
    

    为了按日期字段过滤 Sharepoint 列表项,我没有成功使用 /items/ 中的“createdDateTime”字段。我已经成功过滤了存储在事件字段中的“已创建”时间戳。这是格式: .../items/?$filter=fields/Created lt '2017-12-22'

    所以看看你上面的例子,也许试试:

    .Filter("fields/Created lt '2017-12-22'")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 2018-01-07
      • 2020-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多