[英]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.