gpt4 book ai didi

.net - 在 .Net Core 应用程序中使用 SharePoint CSOM

转载 作者:行者123 更新时间:2023-12-03 17:38:33 26 4
gpt4 key购买 nike

我想通过 .Net Core MVC 应用程序上的 CSOM 库从 SharePoint 列表中获取数据。在 .Net Framework 应用程序上实现这一点绝对没有问题,因为 Microsoft.SharePoint.Client 库包含 ExecuteQuery 方法。不幸的是 .Net Core 不是。

我已经做了异步功能

public async Task<ActionResult> GetRequests()
{
ClientContext context = new ClientContext("https://xxx/sites/xxx/");
List certificatesList = context.Web.Lists.GetByTitle("Items");
CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
ListItemCollection items = certificatesList.GetItems(query);
context.Load(items);
Task spTask = context.ExecuteQueryAsync();
await Task.WhenAll(spTask);
var result = items;
...

}

但它似乎也不适用于 .Net Core,因为它会抛出

Exception thrown: 'System.InvalidOperationException' in >System.Private.CoreLib.ni.dll

Additional information: Cannot find platform service library. For Windows Store application, please include Microsoft.SharePoint.Client.Runtime.WindowsStore.dll in the application package. For Windows Phone application, please include Microsoft.SharePoint.Client.Runtime.WindowsPhone.dll in the application package. For Windows application, please install Microsoft.SharePoint.Client.Runtime.Windows.dll in the GAC (Global Assembly Cache) or make it available for the Windows application.



有人在 .Net Core 中使用 CSOM 还是我应该使用 REST Api?
  "frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}

最佳答案

我有这个问题。出于某种原因,当您引用 Microsoft.SharePointOnline.CSOM nuget 包时,它使用了 .net 框架 dll 而不是 netcore45 dll。
这是我为解决此问题所做的工作:

  • 下载nuget包https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/
  • 将其解压缩到项目中的子文件夹中,例如;依赖
  • 引用正确的程序集

    netcore45\Microsoft.SharePoint.Client.Portable.dll
    netcore45\Microsoft.SharePoint.Client.Runtime.Portable.dll
    net45\Microsoft.SharePoint.Client.Runtime.Windows.dll
    netcore45\Microsoft.SharePoint.Client.Runtime.WindowsStore.dll

  • 哦,如果你已经有了那个 nuget 包,在它上面做一个卸载包。

    关于.net - 在 .Net Core 应用程序中使用 SharePoint CSOM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42186888/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com