1

I've been doing a lot of CSOM application for different clients, and have always been fine using SharePointOnlineCredentials to connect and do my things. However, I created a new project in .net 6 to try it out, and it appears that SharePointOnlineCredentials is no longer availabe. Both Microsoft.Sharepoint.Client and Microsoft.Sharepoint.Client.RunTime are installed, but SharePointOnlineCredentials is not recognised by Visual Studio ...

After browsing through the net, it seems that SharePointOnlineCredentials may be no longer supported on .net 6. Is it true ? Do I have to necessarily go through azure to connect to SharePoint with csom ?

here's a sample of the code :

            string siteUrl = configuation.GetSection("SharePoint").GetSection("siteUrl").Value;
            string UserName = configuation.GetSection("SharePoint").GetSection("userName").Value;
            string clearPwd = configuation.GetSection("SharePoint").GetSection("password").Value;
            string relativeUrl = configuation.GetSection("SharePoint").GetSection("siteRelativeUrl").Value;

            ClientContext context = new ClientContext(siteUrl);
            SecureString pwd = new SecureString();
            foreach (char c in clearPwd.ToCharArray()) pwd.AppendChar(c);
            context.Credentials = new NetworkCredential(UserName, pwd);

This of course returns a 403: forbidden since - I'm guessing - I'm using NetworkCredentials instead of Csom built-in method.

Any help on how to proceed is greatly appreciated.

2 Answers 2

2

This is covered in Using CSOM for .NET Standard instead of CSOM for .NET Framework.

enter image description here

1
  • I see. I guess i'll use modern authentication. Thanks for the help
    – Hallemon
    Sep 22, 2022 at 16:37
0

For anyone still trying to use the old authentication on .Net Core/ Net 6, the easiest solution is to use this re-packed library https://www.nuget.org/packages/TTCUE.NetCore.SharepointOnline.CSOM.16.1.8029.1200 It works exactly like it does in net framework, but it notably lacks the .ExecuteQuery() method, having only the Async version, so you have to do something like

Task.Run(() => clientContext.ExecuteQueryAsync()).Wait();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.