在.Net Core应用程序中使用SharePoint CSOM [英] Using SharePoint CSOM inside .Net Core application

查看:606
本文介绍了在.Net Core应用程序中使用SharePoint CSOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to get data from SharePoint list by CSOM library on .Net Core MVC application. There are absolutely no problem to achieve that on .Net Framework aplication because Microsoft.SharePoint.Client library contains ExecuteQuery method. Unfortunately .Net Core equivalent not.

我已经启用了异步功能

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上运行,因为它会抛出

but it seems like it also won't work on .Net Core because it throws

抛出异常:> System.Private.CoreLib.ni.dll中的'System.InvalidOperationException'

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

其他信息:找不到平台服务库.为了 Windows应用商店应用程序,请包括 Microsoft.SharePoint.Client.Runtime.WindowsStore.dll 应用程序包.对于Windows Phone应用程序,请包括 Microsoft.SharePoint.Client.Runtime.WindowsPhone.dll中的 应用程序包.对于Windows应用程序,请安装 GAC中的Microsoft.SharePoint.Client.Runtime.Windows.dll(全局 程序集缓存)或使其可用于Windows应用程序.

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?

Does someone use CSOM in .Net Core or should I use REST Api instead?

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  }

推荐答案

我遇到了这个问题.由于某些原因,当您引用Microsoft.SharePointOnline.CSOM nuget程序包时,它使用.net框架dll而不是netcore45 dll. 这是我为解决此问题所做的事情:

I had this issue. For some reason when you reference the Microsoft.SharePointOnline.CSOM nuget package it used the .net framework dlls rather than the netcore45 dlls. Here's what I did to work around this:

  1. 下载nuget软件包 https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/
  2. 将其提取到项目中的子文件夹中;例如;依赖关系
  3. 引用正确的程序集

  1. Download the nuget package https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/
  2. Extract it to a subfolder in your project eg; Dependencies
  3. Reference the correct assemblies

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

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软件包,请对其进行卸载.

Oh and if you already have that nuget package do an uninstall-package on it.

这篇关于在.Net Core应用程序中使用SharePoint CSOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆