5

I'm new to Sharepoint online, and don't have an own account (yet), just an username/password from a client.

Need to build a service that gets the folder structure and archives from Sharepoint. And then allows to up/download archives.

Since the package

Microsoft.SharePointOnline.CSOM

is not compatible with .NET Core, I'm using this github solution that seems to cover the main functionality in an equal way: https://github.com/OneBitSoftware/NetCore.CSOM

I think there is nothing wrong with that so far - but when trying to connect using

SharePointOnlineCredentials

...I'm getting the error

PPCRL_REQUEST_E_PARTNER_HAS_NO_ASYMMETRIC_KEY

So I guess there's some account setting missing on the server side? Or am I following a wrong approach? I would have no problem implementing an OAuth access to get a Bearer token, but which API would that be, and how can I register an app for Sharepoint?

My research about API's and this particular error didn't result in anything yet, so I'm reaching out for help here.

Stefan R.
  • 438
  • 1
  • 5
  • 22

2 Answers2

6

Get NuGet package TTCUE.NetCore.SharepointOnline.CSOM.16.1.8029.1200. You can also download an official package Microsoft.SharePointOnline.CSOM but it will attach wrong dlls to your project and you would need to change them according to the link from a different answer here - https://rajujoseph.com/getting-net-core-and-sharepoint-csom-play-nice/

Note - Your .NET Core project will compile, but it doesn't mean that it will work on, for example, linux. Those CSOM dlls are not finished and Microsoft is still working on them.(for a loooong time...)

0xced
  • 25,219
  • 10
  • 103
  • 255
2

Check the example below:

  1. Create a .NET Core console app.

  2. Add the references: Microsoft.SharePoint.Client.Portable.dll, Microsoft.SharePoint.Client.Runtime.Portable.dll, and Microsoft.SharePoint.Client.Runtime.Windows.dll.

    Note: If the project has references to Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll, please remove them.

    These references can be accessed by installing CSOM library into another project, and then navigating to installed nuget packages in the file directory: c:\Users\user\\.nuget\packages\microsoft.sharepointonline.csom\\(version)\lib\netcore45

  3. Add the code below to the .NET Core 2.0 console application:

using System;
using Microsoft.SharePoint.Client;

namespace ConsoleApp1 {
    class Program {
        static void Main(string[] args) {
            string targetSiteURL = @"https://xxx.sharepoint.com/sites/xxx";

            var login = "xxx@xx.onmicrosoft.com";
            var password = "xxx";

            SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, password);

            ClientContext ctx = new ClientContext(targetSiteURL);

            ctx.Credentials = onlineCredentials;

            WebCreationInformation wci = new WebCreationInformation();
            wci.Url = "Site1"; // This url is relative to the url provided in the context
            wci.Title = "Site 1";
            wci.UseSamePermissionsAsParentSite = true;
            wci.WebTemplate = "STS#0";
            wci.Language = 1033;

            var newWeb = ctx.Web.Webs.Add(wci);
            ctx.Load(newWeb, w => w.Title);
            ctx.ExecuteQueryAsync();
            Console.WriteLine("Web title:" + newWeb.Title);
            Console.ReadKey();
        }
    }
}

More information: Getting .NET Core and SharePoint CSOM Play Nice

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
LZ_MSFT
  • 4,079
  • 1
  • 8
  • 9
  • Thank you, but where do I found those dll's? I'm on Mac, but I can also try on Windows – Stefan R. Apr 13 '18 at 12:16
  • @LZ_MSFT Is it possible to get TokenHelper working with net core? Csom is working for me now but i need Token Helper as I require providing the token. – William Jul 24 '19 at 14:28
  • Check the solution from here: https://github.com/SharePoint/PnP/tree/master/Solutions/AspNetCore.Authentication – LZ_MSFT Jul 25 '19 at 01:28