Search code examples
c#sharepointcsom

'AuthenticationManager' does not contain a constructor that takes 0 arguments


I have the following code to connect to SharePoint using clientID and ClientSecret:-

string siteUrl = "https://****l.sharepoint.com/sites/DocumentApprovalProcess/";
string clientId = "***";
string clientSecret = "**";

using (var context = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret))

but i am getting this error:-

'AuthenticationManager' does not contain a constructor that takes 0 arguments   

Solution

  • Please make sure that you installed Office Dev PnP:https://www.nuget.org/packages/SharePointPnPCoreOnline

    You could refer to this article: https://www.c-sharpcorner.com/article/connect-to-sharepoint-online-site-with-app-only-authentication/

    using OfficeDevPnP.Core;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Client;
    
        string siteUrl = "https://tenant.sharepoint.com/sites/demo";  
        using (var cc = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, "[Your Client ID]", "[Your Client Secret]"))  
        {  
            cc.Load(cc.Web, p => p.Title);  
            cc.ExecuteQuery();  
            Console.WriteLine(cc.Web.Title);  
        };