Skip to content

Instantly share code, notes, and snippets.

@vman
Created December 24, 2018 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vman/75e553bca811489814890041a41dcf50 to your computer and use it in GitHub Desktop.
Save vman/75e553bca811489814890041a41dcf50 to your computer and use it in GitHub Desktop.
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;
using System;
namespace AppPermissionsDemo
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite/";
//Client id and Client secret created through appregnew.aspx and permissions granted through appinv.aspx
string clientId = "<client-id>"; //e.g. 15107f17-5230-422b-873c-b3846211cba7
string clientSecret = "<client-secret>"; //e.g. XeGMHUxRPOg0o1LeKqfWVYTzO0blGfXBPKvNiCQwHtc=
var authManager = new AuthenticationManager();
//PnP Core method
ClientContext clientContext = authManager.GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret);
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQueryRetry();
Console.WriteLine(web.Title);
}
}
}
@dnyaneshwar-surywanshi
Copy link

Hi I am using above code but getting below error.
System.TypeInitializationException: The type initializer for 'OfficeDevPnP.Core.Utilities.TokenHelper' threw an exception.
---> System.TypeLoadException: Could not load type 'System.Web.Configuration.WebConfigurationManager' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at OfficeDevPnP.Core.Utilities.TokenHelper..cctor()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment