Microsoft.Sharepoint.Client.Context.Load 使用 F# 时出错

Microsoft.Sharepoint.Client.Context.Load error using F#

我正在尝试使用 CSDOM Microsoft.Sharepoint.Client SDK 从 Sharepoint 提取一些文档。

我有一个基本查询设置如下:

let uri = @"XXXXXX"
let userName = XXXXXX
let password = XXXXXX
let networkCredential = new NetworkCredential(userName, password)
let context = new ClientContext(uri)
context.Credentials <- networkCredential
let list = context.Web.Lists.GetByTitle("XXXXXX")
let listItemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery())
context.Load(listItemCollection)
context.ExecuteQuery()

我在加载方法上收到此错误消息

error FS0193: internal error: GenericArguments[0], 'Microsoft.SharePoint.Client.ListItemCollection', on 'Void Load[T](T, System.Linq.Expressions.Expression1[System.Func2[T,System.Object]][])' violates the constraint of type 'T'.

我想我也必须传入 linq 表达式?这似乎有很多不必要的步骤,因为我只想从文件夹中获取文档列表以进行迭代。

有人有替代代码吗?

好的,我可以使用 让它工作。这是我的工作代码:

open System
open System.Linq.Expressions

type Expr = 
    static member Quote(e:Expression<System.Func<_, _>>) = e

// ...
// Authentication logic goes here. Personally, I had to use
// SharePointOnlineCredentials instead of NetworkCredential.
// ...

let items =
    let list = context.Web.Lists.GetByTitle("Documents")
    list.GetItems(CamlQuery())
let getDisplayName =
    Expr.Quote(
        fun (item : ListItem) ->
            item.DisplayName :> obj)
context.Load(
    items,
    fun (items : ListItemCollection) ->
        items.Include(getDisplayName) :> obj)
context.ExecuteQuery()
for item in items do
    printfn "%s" item.DisplayName

它不是很漂亮,但它完成了工作。