pnp / pnpframework

PnP Framework is a .NET library targeting Microsoft 365 containing the PnP Provisioning engine and a ton of other useful extensions
https://pnp.github.io/pnpframework/
MIT License
205 stars 142 forks source link

Getting Access Denied error while checking out Master Page Gallery using pnp C# code #1060

Open vvenkataratnam opened 1 week ago

vvenkataratnam commented 1 week ago

We had C# code to provision a new site using PnP C# library with XMLTemplateProvider, that used to work from past 6+ years. Recently, we are facing the following error while trying to check out the Master Page Gallery.

Error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Appreciate, if someone could share why we are getting this error and what has changed recently in SharePoint?


using (var repositoryContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(templatesSiteUrl,clientId,clientSecret))  {
    var mpgallery = web.GetListByTitle("Master Page Gallery");   
    mpgallery.ForceCheckout = true;   
    mpgallery.Update();   
    web.Context.ExecuteQueryRetry();
}
pkbullock commented 1 week ago

Hi, you will need to provide an alternative service principal since the app PnP Management Shell has been removed: https://pnp.github.io/powershell/articles/registerapplication.html

vvenkataratnam commented 1 week ago

Hi Paul, Thanks for the reply. After Setting up access using our own Entra ID App for App Only Access, can we use pnp framework in C# and perform force checkout on master page gallery?