Having recently moved our intranet from SharePoint on-premises to SharePoint Online, I'm now trying to get a bunch of C# Console Apps (.NET Framework) to work with the new version of the sites. I believe I can use the PnP Framework to do this but I'm struggling to connect to SharePoint Online successfully. I've set up an App Registration in Azure and I'm using the ClientID and ClientSecret in my code, which is as follows:
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PnP.Framework;
namespace SPOTest3_pnp
{
internal class Program
{
static void Main(string[] args)
{
string siteUrl = @"https://mycompany.sharepoint.com/sites/mysite";
string clientId = "12345678-1234-1234-1234-123456789012";
string clientSecret = "1234567890123456789012345678901234567890";
using (var clientContext = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientId, clientSecret))
{
clientContext.Load(clientContext.Web, p => p.Title);
clientContext.ExecuteQuery();
Console.WriteLine(clientContext.Web.Title);
};
}
}
}
The call to ExecuteQuery()
however return this error:
Microsoft.SharePoint.Client.ClientRequestException: 'Cannot contact site at the specified URL https://mycompany.sharepoint.com/sites/mysite. The app principal does not exist.'
I can't find anything useful to explain what that error refers to in this case or how to fix it. Any help would be gratefully received.