### Install PnP Framework and CSOM Packages Source: https://github.com/pnp/pnpframework/blob/dev/docs/notebooks/Getting-Started-with-PnP-Framework.ipynb Installs necessary NuGet packages for PnP Framework, CSOM, and configuration management. Ensure you have a .NET environment set up. ```csharp #r "nuget: Microsoft.SharePointOnline.CSOM, 16.1.23814.12000" #r "nuget: PnP.Framework, 1.13.0" #r "nuget: Microsoft.Extensions.Configuration, 7.0.0" #r "nuget: Microsoft.Extensions.Configuration.Json, 7.0.0" using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; using Microsoft.SharePoint.Client; using PnP.Framework; using System.IO; ``` -------------------------------- ### App-only authentication with PnP Sites Core Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/migrating-from-pnp-sites-core.md Example of app-only authentication using PnP Sites Core with a certificate. ```csharp var authManager = new AuthenticationManager(); using (var context = authManager.GetSharePointOnlineAuthenticatedContextTenant("https://contoso.sharepoint.com", "", "contoso.onmicrosoft.com", "c:\\temp\\mycert.pfx", "pfx pwd")) { } ``` -------------------------------- ### PnP Sites Core Delegated Authentication Example Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/migrating-from-pnp-sites-core.md Illustrates the authentication method used in PnP Sites Core, which involves providing credentials directly to the AuthenticationManager. ```csharp var authManager = new AuthenticationManager(); using (var context = authManager.GetSharePointOnlineAuthenticatedContextTenant("https://contoso.sharepoint.com", "joe@contoso.onmicrosoft.com", "pwd")) { } ``` -------------------------------- ### Provisioning a Classic Team Site with PnP PowerShell Source: https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework.Modernization.Test/Provision/Readme.md Connect to a SharePoint Online team site and apply a provisioning template using PnP PowerShell. Ensure you have the PnP PowerShell module installed and replace placeholders with your tenant and site information. ```powershell Connect-PnPOnline https://.sharepoint.com/sites/ Apply-PnProvisioningTemplate -Path "ClassicTeamSite-SampleData.xml" ``` -------------------------------- ### Add PnP.Framework and related NuGet packages Source: https://github.com/pnp/pnpframework/blob/dev/docs/notebooks/Getting-Started-with-PnP-Provisioning.ipynb Add necessary PnP.Framework and related NuGet packages for PnP Provisioning operations. Ensure you have the correct versions installed. ```csharp #r "nuget: Microsoft.SharePointOnline.CSOM, 16.1.23814.12000" #r "nuget: PnP.Framework, 1.13.0" #r "nuget: Microsoft.Extensions.Configuration, 7.0.0" #r "nuget: Microsoft.Extensions.Configuration.Json, 7.0.0" using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; using Microsoft.SharePoint.Client; using PnP.Framework; using PnP.Framework.Provisioning.Model; using PnP.Framework.Provisioning.Providers; using PnP.Framework.Provisioning.Providers.Xml; using PnP.Framework.Provisioning.ObjectHandlers; using PnP.Framework.Provisioning.Connectors; using Model = PnP.Framework.Provisioning.Model; using File = System.IO; ``` -------------------------------- ### PnP Framework Delegated Authentication Example Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/migrating-from-pnp-sites-core.md Demonstrates the updated delegated authentication in PnP Framework, which uses Azure AD client ID and a SecureString for the password, with a generic GetContext method. ```csharp var authManager = new AuthenticationManager("", "joe@contoso.onmicrosoft.com", "Pwd as SecureString"); using (var context = authManager.GetContext("https://contoso.sharepoint.com")) { } ``` -------------------------------- ### App-only authentication with PnP Framework Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/migrating-from-pnp-sites-core.md Example of app-only authentication using PnP Framework with a certificate. This version uses the AuthenticationManager constructor that takes client ID, certificate path, password, and tenant. ```csharp var authManager = new AuthenticationManager("", "c:\\temp\\mycert.pfx", "pfx pwd", "contoso.onmicrosoft.com"); using (var context = authManager.GetContext("https://contoso.contoso.com")) { } ``` -------------------------------- ### Copy Certificate Thumbprint to Clipboard Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/migrating-from-pnp-sites-core.md Copies the thumbprint of the generated X.509 certificate to the clipboard. This is needed for authentication setup. ```powershell $app.'Certificate Thumbprint' | clip ``` -------------------------------- ### Configure App Settings for PnP Framework Notebooks Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/setting-up-to-use-polyglot-samples.md Copy the sample settings file and update it with your Azure AD App Registration details, certificate information, tenant name, and SharePoint site URL. ```json { "azureAppId":"", "certificatePassword":"", "certificatePath":"C:\\temp\\PolyGlot\\pnpframework-polyglot.pfx", "azureTenantName":"contoso.onmicrosoft.com", "siteUrl" : "https://contoso.sharepoint.com/sites/contoso" } ``` -------------------------------- ### Create a site template from an existing SharePoint site Source: https://github.com/pnp/pnpframework/blob/dev/docs/notebooks/Getting-Started-with-PnP-Provisioning.ipynb Extracts the configuration of an existing SharePoint site into a PnP Provisioning XML template. This process can take 15-30 seconds depending on site complexity. ```csharp string path = "pnpframework-sample-template.xml"; var authManager = new AuthenticationManager(appId, certPath, certPassword, tenantName); using (var clientContext = authManager.GetContext(siteUrl)) { // Used to control the output of the template ProvisioningTemplateCreationInformation creationInformation = new ProvisioningTemplateCreationInformation(clientContext.Web); // Captures ALL the configuration information from the site ProvisioningTemplate template = clientContext.Web.GetProvisioningTemplate(creationInformation); // Output the template as XML to the file System XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(".",""); provider.SaveAs(template,path); } ``` -------------------------------- ### Create and apply an in-memory site template Source: https://github.com/pnp/pnpframework/blob/dev/docs/notebooks/Getting-Started-with-PnP-Provisioning.ipynb Defines a site template in memory, serializes it to an XML file, applies it to a SharePoint site, and then deletes the temporary XML file. This demonstrates creating and applying templates programmatically. ```csharp var authManager = new AuthenticationManager(appId, certPath, certPassword, tenantName); using (var clientContext = authManager.GetContext(siteUrl)) { // Define the site template ProvisioningTemplate template = new ProvisioningTemplate(); template.Id = "ExampleTemplatePnPFramework"; template.Version = 1.0; template.Scope = Model.ProvisioningTemplateScope.RootSite; template.BaseSiteTemplate = "SITEPAGEPUBLISHING#0"; var listInstance = new ListInstance() { Title = "Example List", TemplateType = 100, // Document Library 101 Url = "Lists/ExampleList", ContentTypesEnabled = true, FieldRefs = { new FieldRef("Title") }, EnableVersioning = true, MaxVersionLimit = 250, OnQuickLaunch = true }; template.Lists.Add(listInstance); // Optionally - Serialize the site template to an XML file and save it to the file system string templateFileName = "ExampleTemplatePnPFramework.xml"; XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(".", ""); provider.SaveAs(template, templateFileName); // Apply the template to the target site var applyingInformation = new ProvisioningTemplateApplyingInformation(); clientContext.Web.ApplyProvisioningTemplate(template, applyingInformation); // Delete the XML file System.IO.File.Delete(templateFileName); }; ``` -------------------------------- ### Working DocFX Build Versions Source: https://github.com/pnp/pnpframework/blob/dev/docs/Notes.md Commands for generating metadata and building the project with a specific DocFX version. ```bash C:\Git\docfx\2.59.3\docfx metadata docfx.json ``` ```bash C:\Git\docfx\2.59.3\docfx build docfx.json ``` -------------------------------- ### Load Configuration from appsettings.json Source: https://github.com/pnp/pnpframework/blob/dev/docs/notebooks/Getting-Started-with-PnP-Framework.ipynb Loads Azure AD application credentials and SharePoint Online site URL from an appsettings.json file. Ensure the appsettings.json file exists in the current directory and contains the required keys. ```csharp // Credentials var config = new ConfigurationBuilder() .AddJsonFile(Path.Combine(Directory.GetCurrentDirectory(),"appsettings.json")) .Build(); var appId = config["azureAppId"]; var certPassword = config["certificatePassword"]; var certPath = config["certificatePath"]; var tenantName = config["azureTenantName"]; // SharePoint Online Site URL var siteUrl = config["siteUrl"]; // To setup an Azure AD app, please visit XXX ``` -------------------------------- ### Run DocFX Metadata Command Source: https://github.com/pnp/pnpframework/blob/dev/docs/Notes.md Command to generate metadata for the project using DocFX. ```bash C:\Git\docfx\2.59.4\docfx metadata docfx.json ``` -------------------------------- ### Add PnP.Framework NuGet Package to .NET Interactive Notebook Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/setting-up-to-use-polyglot-samples.md Use this command to reference the PnP.Framework NuGet package in your .NET Interactive Notebook. Update the version number to the latest available. ```dotnetcli #r "nuget: PnP.Framework, 1.13.xx-nightly" ``` -------------------------------- ### Add PnP.Framework NuGet Package Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/readme.md Reference the PnP.Framework NuGet package in your .NET project to use its functionalities. Ensure you specify the desired version. ```dotnetcli dotnet add package PnP.Framework --version 1.13.xx-nightly ``` -------------------------------- ### Refresh Object Model with XSD Source: https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/Provisioning/Providers/Xml/readme.md Use this command to refresh the object model after updating the ProvisioningSchema.xsd file. Ensure the XSD tool is available in your PATH. ```cmd xsd -c ProvisioningSchema-2022-09.xsd /n:PnP.Framework.Provisioning.Providers.Xml.V202209 ``` -------------------------------- ### Load Azure AD and SharePoint Online credentials Source: https://github.com/pnp/pnpframework/blob/dev/docs/notebooks/Getting-Started-with-PnP-Provisioning.ipynb Load Azure AD application credentials and SharePoint Online site URL from an appsettings.json file. Ensure the appsettings.json file is correctly configured. ```csharp // Credentials var config = new ConfigurationBuilder() .AddJsonFile(File.Path.Combine(File.Directory.GetCurrentDirectory(),"appsettings.json")) .Build(); var appId = config["azureAppId"]; var certPassword = config["certificatePassword"]; var certPath = config["certificatePath"]; var tenantName = config["azureTenantName"]; // SharePoint Online Site URL var siteUrl = config["siteUrl"]; ``` -------------------------------- ### Connect to SharePoint Online Site Source: https://github.com/pnp/pnpframework/blob/dev/docs/notebooks/Getting-Started-with-PnP-Framework.ipynb Establishes a connection to a SharePoint Online site using provided Azure AD application credentials and retrieves the site title. Requires a configured AuthenticationManager and site URL. ```csharp var authManager = new AuthenticationManager(appId, certPath, certPassword, tenantName); using (var clientContext = authManager.GetContext(siteUrl)) { Web web = clientContext.Web; clientContext.Load(web, w => w.Title); clientContext.ExecuteQuery(); Console.WriteLine("Site title: {0}", web.Title); }; ``` -------------------------------- ### Register Azure AD App for App-Only Access Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/migrating-from-pnp-sites-core.md Use the Register-PnPAzureADApp cmdlet to register an application in Azure AD for app-only access. This command creates a self-signed certificate and configures necessary permissions. ```powershell $app = Register-PnPAzureADApp -ApplicationName "PnP.Framework.Consumer" -Tenant contoso.onmicrosoft.com -OutPath c:\temp -CertificatePassword (ConvertTo-SecureString -String "password" -AsPlainText -Force) -GraphApplicationPermissions "Group.ReadWrite.All", "User.ReadWrite.All" -SharePointApplicationPermissions "Sites.FullControl.All", "TermStore.ReadWrite.All", "User.ReadWrite.All" -Store CurrentUser -DeviceLogin ``` -------------------------------- ### Copy Application ID to Clipboard Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/migrating-from-pnp-sites-core.md Copies the Application ID (Client ID) of the registered Azure AD app to the clipboard for later use. ```powershell $app.AzureAppId | clip ``` -------------------------------- ### Transform Classic Publishing Page to Modern Page Source: https://github.com/pnp/pnpframework/blob/dev/docs/using-the-framework/pnp-modernization/getting-started.md This C# code snippet demonstrates how to transform a classic publishing page to a modern page using the PublishingPageTransformator. It includes options for overwriting existing pages, mapping terms and URLs, and publishing the created page. ```csharp // Converts a publishing page to modern page example using (var targetClientContext = GetClientContext("https://.sharepoint.com/sites/modernsite")) { using (var sourceClientContext = GetClientContext("https://.sharepoint.com/sites/classic-site")) { var pageTransformator = new PublishingPageTransformator(sourceClientContext, targetClientContext , @"path\to\mapping\custom-page-layout-mapping.xml"); // pageTransformator.RegisterObserver(new MarkdownObserver(folder: "d:\\temp", includeVerbose:true)); var pages = sourceClientContext.Web.GetPagesFromList("Pages", ""); foreach (var page in pages) { // Options for transformation PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page) { // If target page exists, then overwrite it Overwrite = true, KeepPageCreationModificationInformation = true, PostAsNews = true, TermMappingFile = @"path\to\mapping\term_mapping.csv", UrlMappingFile = @"path\to\mapping\url_mapping.csv", UserMappingFile = @"path\to\mapping\user_mapping.csv", DisablePageComments = true, PublishCreatedPage = true, }; pti.MappingProperties["SummaryLinksToQuickLinks"] = "true"; pti.MappingProperties["UseCommunityScriptEditor"] = "true"; // Transform the page var result = pageTransformator.Transform(pti); } // Writes output to logs pageTransformator.FlushObservers(); } } ``` -------------------------------- ### JavaScript for Page Load Animations Source: https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework.Test/Resources/TestHtmlPublishingPageLayout.html JavaScript object defining parameters for page load animations. Specifies elements that should slide in from the side. ```javascript // ``` -------------------------------- ### CSS for Page Animation Source: https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework.Test/Resources/TestHtmlPublishingPageLayout.html CSS rules to control page element transparency during animations. Used to manage the visibility of elements based on whether the client is a bot. ```css // ``` -------------------------------- ### JavaScript Form Submission Hook Source: https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework.Test/Resources/TestHtmlPublishingPageLayout.html JavaScript code to override the form's submit function. It allows a custom hook to intercept submissions and conditionally call the original submit function. ```javascript // ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.