pnp / PnP-Provisioning-Schema

Office 365 Patterns and Practices - Remote Provisioning Schema
MIT License
159 stars 220 forks source link

How to add SPFx webpart to modern sharepoint page using C#? #547

Open DesireTusharG opened 3 years ago

DesireTusharG commented 3 years ago

because we learn from other sources that client side page library is not compatible in new pnp version. At the same time we are using AngleSharp package which support new version >=0.14.0. In new version of Pnp, AngleSharp version supported is >=0.14.0 and in old version of Pnp, AngleSharp version supported is <0.14.0.

OfficeDevPnP.Core.Pages.ClientSidePage page = OfficeDevPnP.Core.Pages.ClientSidePage.Load(clientContext, "4Mata.aspx"); var components = page.AvailableClientSideComponents(); string wpName = "4Mata"; List componentsnames = components.Select(k => k.Name).ToList(); var webPartToAdd = components.Where(wp => wp.ComponentType == 1 && wp.Name == wpName).FirstOrDefault(); if (webPartToAdd != null) { OfficeDevPnP.Core.Pages.ClientSideWebPart clientWp = new OfficeDevPnP.Core.Pages.ClientSideWebPart(webPartToAdd) { Order = -1 }; page.AddControl(clientWp); } page.Save(pageName+".aspx"); clientContext.ExecuteQuery(); page.Publish();

Error occurred in line of code: page.Save(pageName+".aspx"); Error: 'Could not load type 'System.Web.UI.HtmlTextWriter' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.'

If we use older version of SharePointPnpCoreOnline package then following error occurred:

Error occured in line of code: OfficeDevPnP.Core.Pages.ClientSidePage page = OfficeDevPnP.Core.Pages.ClientSidePage.Load(clientContext, "4Mata.aspx"); Error: 'Could not load type 'AngleSharp.Parser.Html.HtmlParserOptions' from assembly 'AngleSharp, Version=0.15.0.0, Culture=neutral,

Question -> How we can create modern page because both pnp library not working correctly? -> How we can add spfx webpart in modern page?

Please let us know the solution for this if possible.

Thanks in advance

RasheedSiriyala commented 2 years ago

Hi Tushar, I can able to create modern page using CSOM solution. But couldn't add SPFx webpart and it is showing same error '"Could not load type 'System.Web.UI.HtmlTextWriter' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.":"System.Web.UI.HtmlTextWriter"'

Any successful attempt from you?

Thanks