Sharepoint CSOM Authentication issue with .NET Core
Solution 1
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...)
Solution 2
Check the example below:
Create a .NET Core console app.
-
Add the references:
Microsoft.SharePoint.Client.Portable.dll
,Microsoft.SharePoint.Client.Runtime.Portable.dll
, andMicrosoft.SharePoint.Client.Runtime.Windows.dll
.Note: If the project has references to
Microsoft.SharePoint.Client.dll
andMicrosoft.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
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 = "[email protected]";
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
Stefan R.
Updated on June 14, 2022Comments
-
Stefan R. almost 2 years
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. about 6 yearsThank you, but where do I found those dll's? I'm on Mac, but I can also try on Windows
-
William almost 5 years@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.
-
LZ_MSFT almost 5 yearsCheck the solution from here: github.com/SharePoint/PnP/tree/master/Solutions/…
-
Adrian Stanisławski over 3 yearsI think this solution is no longer needed as CSOM for .NET Core is already released.
-
Glenn Ferrie about 3 yearsPlease send a liink or name for that package. I am relying on this one for now.
-
Adrian Stanisławski almost 3 years@GlennFerrie - The newest package is Pnp.Framework. Or the deprecated one but still working - SharePointPnpCoreOnline. It is not exactly the same as the old one but I would recommend using PnP.