Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vvenkataratnam opened this issue Sep 10, 2024 · 4 comments

Comments

@vvenkataratnam
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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?

@jansenbe
Copy link
Contributor

If you grant it the needed permissions then yes

@vvenkataratnam
Copy link
Author

vvenkataratnam commented Sep 18, 2024

I have created the new app registration in Azure and set it up for App Only Access and using the following powershell script to check out the master page gallery.

Connect-PnPOnline -ClientId $ClientID -CertificatePath $CertificationPath -CertificatePassword (ConvertTo-SecureString -AsPlainText "XYZ" -Force) -Url $SiteURL -Tenant $Tenant
Get-PnPList

# Set the Master Page Gallery (/_catalogs/masterpage) to require checkout
Set-PnPList -Identity "Master Page Gallery" -ForceCheckout $true

I am able to see the lists, but still getting Access Denied, when trying to use Set-PnPList

What are the other permissions, I need to set, so that I can use Set-PnPList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants