简体   繁体   English

Microsoft.Sharepoint.Client.Context.Load 错误使用 F#

[英]Microsoft.Sharepoint.Client.Context.Load error using F#

I am trying to pull some documents from Sharepoint using the CSDOM Microsoft.Sharepoint.Client SDK.我正在尝试使用 CSDOM Microsoft.Sharepoint.Client SDK 从 Sharepoint 中提取一些文档。

I have a basic query set up like this:我有一个这样的基本查询设置:

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()

I am getting this error message on the load method我在加载方法上收到此错误消息

error FS0193: internal error: GenericArguments[0], 'Microsoft.SharePoint.Client.ListItemCollection', on 'Void Load[T](T, System.Linq.Expressions.Expression 1[System.Func 2[T,System.Object]][])' violates the constraint of type 'T'.错误 FS0193:内部错误:GenericArguments [0],'Microsoft.SharePoint.Client.ListItemCollection',在'无效负载 [T](T,System.Linq.Expressions.Expression 1[System.Func TSystem.Func.Object. ]][])' 违反了类型 'T' 的约束。

I think I have to pass in the linq expression also?我想我还必须传递 linq 表达式吗? This seems like a lot of unneeded steps as all I want to do is get a list of documents from a folder to iterate.这似乎有很多不需要的步骤,因为我想做的就是从文件夹中获取要迭代的文档列表。

Anyone have any alternative code?任何人有任何替代代码?

OK, I was able to get this to work using this answer .好的,我能够使用这个答案让它工作。 Here's my working code:这是我的工作代码:

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

It ain't pretty, but it gets the job done.它不漂亮,但它完成了工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 F# 和 PnP SharePoint - F# and PnP SharePoint Microsoft.SharePoint.Client.ClientRequestException错误 - Microsoft.SharePoint.Client.ClientRequestException Error 该应用程序因错误而终止。无法加载文件或程序集&#39;Microsoft.SharePoint.Client,版本= 14.0.0.0, - The application terminated with an error.Could not load file or assembly 'Microsoft.SharePoint.Client, Version=14.0.0.0, Connect-SPOService 错误:无法加载类型“Microsoft.SharePoint.Client.SharePointOnlineCredentials” - Connect-SPOService error:Could not load type 'Microsoft.SharePoint.Client.SharePointOnlineCredentials 无法在Powershell脚本中加载Microsoft.SharePoint.Client.dll - Cannot load Microsoft.SharePoint.Client.dll in powershell script 使用客户端上下文检索共享点列表数据 - To retreive sharepoint list data using client context 使用 Microsoft.SharePoint.Client 将图像上传到共享点文件夹 - Uploading Image using Microsoft.SharePoint.Client to a sharepoint folder 如何使用 Microsoft Graph API 和 Graph Client 添加 SharePoint 选项卡? - How to add a SharePoint tab using Microsoft Graph API and Graph Client? 使用客户端上下文和CAML查询删除共享点列表中的所有行 - Delete all rows in sharepoint list using Client Context and CAML Query 使用 Powershell 将文件上传到 Sharepoint Online (Microsoft 365)(选项 4 - 使用 Microsoft.SharePoint.Client.ClientContext) - Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 4 - Using Microsoft.SharePoint.Client.ClientContext)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM