PnP
PnP copied to clipboard
ClientSidePage.Load issue
- PnP Sites Core - https://github.com/OfficeDev/PnP-Sites-Core
Category
[ x ] Bug [ ] Enhancement
Environment
[ x ] Office 365 / SharePoint Online [ ] SharePoint 2016 [ ] SharePoint 2013
Expected or Desired Behavior
I have created an Azure function, which connects to a SharePoint Online communication site and tries to load and existing page from the Site Pages lists in order to modify it as per example here https://github.com/SharePoint/PnP/blob/5cde81a38b708a8e0f9d169a42db4514b7332fb6/Samples/Provisioning.ModernPages/Provisioning.ModernPages/Program.cs , but using Certificate and App Permissions instead of username and password.
Observed Behavior
When the execution gets to
ClientSidePage csp = ClientSidePage.Load(ctx, file.Name);
I have the following error:
2019-01-30T09:34:05.538 [Error] Message : Object reference not set to an instance of an object.
2019-01-30T09:34:05.632 [Error] Stack : at OfficeDevPnP.Core.Pages.ClientSidePage.<>c__DisplayClass93_0.<LoadFromHtml>b__1(CanvasSection p)
at System.Linq.Enumerable.WhereListIterator1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1 source)
at OfficeDevPnP.Core.Pages.ClientSidePage.LoadFromHtml(String html, String pageHeaderHtml)
at OfficeDevPnP.Core.Pages.ClientSidePage.Load(ClientContext cc, String pageName)
at Submission#0.Run(String myQueueItem, TraceWriter log) in D:\home\site\wwwroot\QueueTriggerCS\run.csx:line 88.
2019-01-30T09:34:05.663 [Error] Stack : at OfficeDevPnP.Core.Pages.ClientSidePage.<>c__DisplayClass93_0.<LoadFromHtml>b__1(CanvasSection p)
at System.Linq.Enumerable.WhereListIterator1.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1 source)
at OfficeDevPnP.Core.Pages.ClientSidePage.LoadFromHtml(String html, String pageHeaderHtml)
at OfficeDevPnP.Core.Pages.ClientSidePage.Load(ClientContext cc, String pageName)
at Submission#0.Run(String myQueueItem, TraceWriter log) in D:\home\site\wwwroot\QueueTriggerCS\run.csx:line 88
Steps to Reproduce
In my Azure function I have the following dependencies:
"{ "frameworks": { "net46": { "dependencies": { "SharePointPnPCoreOnline": "3.3.1811", "Microsoft.IdentityModel.Clients.ActiveDirectory" : "3.19.8", "System.Security.Cryptography.X509Certificates" : "4.3.2", "AngleSharp" : "0.9.9" } } } }"
The relevant code in the Azure function:
**_OfficeDevPnP.Core.AuthenticationManager authmanager = new OfficeDevPnP.Core.AuthenticationManager();
using (ClientContext ctx = authmanager.GetAzureADAppOnlyAuthenticatedContext(siteUrl, applicationID, tenant, cert2)) { ctx.Load(ctx.Web); ListCollection collList = ctx.Web.Lists;
ctx.Load(collList,lists => lists.Include(list => list.Title, list => list.Id));
List sitePagesList = ctx.Web.Lists.GetByTitle("Site pages");
ctx.Load(sitePagesList);
ctx.Load(sitePagesList.RootFolder);
try{
ctx.ExecuteQuery();
ListItem li = sitePagesList.GetItemById(2);
ctx.Load(li);
ctx.ExecuteQuery();
Microsoft.SharePoint.Client.File file = li.File;
ctx.Load(file, f => f.Name);
ctx.ExecuteQuery();
ClientSidePage csp = ClientSidePage.Load(ctx, file.Name);
}
catch(Exception ex){}
}_**
Thank you in advance for your help as I am new to Azure functions.
Br, Anisia Pop
Hi,
i have to add some more information after some testing: If I am authenticating with user name and password like bellow, the lines in previous post work just fine OfficeDevPnP.Core.AuthenticationManager authManager = new OfficeDevPnP.Core.AuthenticationManager(); ClientContext ctx = authManager.GetSharePointOnlineAuthenticatedContextTenant("<SPOSiteUrl>", "user", "password");
Do I need to do something extra in order for the get with App permissions to work? Thank you in advance.
Br, Anisia Pop