我想通过 .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,因为它会抛出
抛出异常:>System.Private.CoreLib.ni.dll 中的“System.InvalidOperationException”
附加信息:找不到平台服务库。为了
Windows 应用商店应用程序,请包含
Microsoft.SharePoint.Client.Runtime.WindowsStore.dll 在
应用程序包。对于 Windows Phone 应用程序,请包含
Microsoft.SharePoint.Client.Runtime.WindowsPhone.dll 在
应用程序包。对于 Windows 应用程序,请安装
GAC(全局)中的 Microsoft.SharePoint.Client.Runtime.Windows.dll
程序集缓存)或使其可用于 Windows 应用程序。
有人在 .Net Core 中使用 CSOM 还是我应该使用 REST Api?
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
我有这个问题。由于某种原因,当您引用 Microsoft.SharePointOnline.CSOM nuget 包时,它使用 .net Framework dll 而不是 netcore45 dll。
以下是我为解决此问题所做的操作:
- 下载nuget包https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/ 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 包,请对其进行卸载包。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)