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

Fix #1562 #1563

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ internal async static Task<IPage> NewPageAsync(PnPContext context, PageLayoutTyp
return new Page(context, pagesLibrary, null, pageLayoutType);
}

private static async Task<IList> EnsurePagesLibraryAsync(PnPContext context)
private static async Task<IList> EnsurePagesLibraryAsync(PnPContext context, bool firstTry = true)
{
IList pagesLibrary = null;
var lists = context.Web.Lists.AsRequested();
Expand Down Expand Up @@ -530,6 +530,17 @@ private static async Task<IList> EnsurePagesLibraryAsync(PnPContext context)
}
}

// Still no pages library found, maybe it doesn't exist?
if (pagesLibrary == null && firstTry)
{
var sitePagesFeatureId = Guid.Parse(PageConstants.SitePagesFeatureId);
var activatedFeatureIds = context.Web.Features.ToList().Select(x => x.DefinitionId);
if (!activatedFeatureIds.Contains(sitePagesFeatureId)) await context.Web.Features.EnableAsync(sitePagesFeatureId).ConfigureAwait(false);

// Now we should have the pages library
pagesLibrary = await EnsurePagesLibraryAsync(context, false).ConfigureAwait(false);
}

return pagesLibrary;
}

Expand Down