Search Results for

    Show / Hide Table of Contents

    PnP Core SDK - Console Sample

    This solution demonstrates how the PnP Core SDK can be used in a console application. In this sample we're querying a modern group connected SharePoint site which also has Teams. If you're testing this code against a modern communication site or another classic site then please comment out the "teams" parts.

    Source code

    You can find the sample source code here: /samples/Demo.Console

    Run the sample

    Register and configure an AAD app

    In order for the user to authenticate on the App, A new app registration should be created on Azure Portal

    • Go to Azure Active Directory Portal

    • In App registrations, click New registration

    • Enter a name for your new app, make sure Accounts in this organizational directory only is selected. As the Redirect URI, change from Web Platform to "Mobile and Desktop Applications" use http://localhost for the redirect URI (only needed if you want use an interactive authentication flow)

    • Under Implicit grant section, check ID tokens and Access tokens

    • Under Advanced settings section, set Allow public client flows to yes

    • Go to API permissions section , click Add a permission

      • Select Microsoft Graph > Delegated permissions > select Directory.Read.All
      • Select Microsoft Graph > Delegated permissions > select User.Read
      • Select Microsoft Graph > Delegated permissions > select ChannelMessage.Read.All
      • Select Microsoft Graph > Delegated permissions > select ChannelMessage.Send
      • Select Microsoft Graph > Delegated permissions > select TeamSettings.ReadWrite.All
      • Select Microsoft Graph > Delegated permissions > select TeamsTab.ReadWrite.All
      • Select Microsoft Graph > Delegated permissions > select Sites.Read.All
      • Select Microsoft Graph > Delegated permissions > select Files.Read.All
      • Select SharePoint > Delegated permissions > select AllSites.Read
    • Click Grant admin consent for {tenant}

    • From Overview,

      • copy the value of Directory (tenant) ID
      • copy the value of Application (client) ID

    Configure your application

    • This demo application comes with code for 2 different authentication providers, the CredentialManagerAuthenticationProvider or the InteractiveAuthenticationProvider can be used. The latter is the default value. To configure the app update the appsettings.json file with:

    • Configure the Tenant ID of your app as the value of CustomSettings:TenantId in appsettings.json setting

    • Configure the Client ID of your app as the value of CustomSettings:ClientId in appsettings.json setting

    • Configure the URL of a target Microsoft SharePoint Online modern team site collection as the value of CustomSettings:DemoSiteUrl in appsettings.json setting

    • Configure the URL of a target Microsoft SharePoint Online sub site as the value of CustomSettings:DemoSubSiteUrl in appsettings.json setting

    Be sure to have a Team in Microsoft Teams backing the modern team site in the above site collection

    Execute

    Hit F5 in Visual studio to execute the console app. The app will prompt for an interactive login (via a browser window).

    preview image of the running app

    Back to top PnP Core SDK
    Generated by DocFX with Material UI
    spacer