Created
December 24, 2018 12:29
-
-
Save vman/75e553bca811489814890041a41dcf50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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()