M365 – SharePoint Online – Resolving exception “NoComponentId” while creating new client side page in Site Pages Library using CSOM

Hi All,
LIFE IS BEAUTIFUL 🙂 I hope we all are safe 🙂 STAY SAFE, STAY HEALTHY, STAY HOME 🙂
Today new issue 🙂 and resolution 🙂
Background / Use Case / Requirement:
- In one of our SharePoint online project we have requirement when SharePoint modern communication site is created, one client side page in Site Pages library should be created / provisioned
- We have used following code, we are using CSOM in our background job
List pagesLibrary = getSitePagesLibrary(siteUrl, cc);
cc.Load(pagesLibrary, pagesLibrary => pagesLibrary.RootFolder.Files);
cc.ExecuteQuery();
ListItem newClientPage = pagesLibrary.RootFolder.Files.AddTemplateFile
cc.Web.ServerRelativeUrl + "/SitePages/KnowledgeJunction.aspx",
TemplateFileType.ClientSidePage).ListItemAllFields;
newClientPage.Update();
cc.Load(newClientPage);
cc.ExecuteQuery();
While executing the above code there were no exception in code, page is getting successfully provisioned in Site Pages library.
But issue is when we try to open the page we are getting an following error:

We were wondering if new client side page is provisioned successfully then why this error.
Solution:
So again Google our friend 🙂 and found that following property of the client side page is need to set
newClientPage["ClientSideApplicationId"] = "<GUID>";
So final working code is
List pagesLibrary = getSitePagesLibrary(siteUrl, cc);
cc.Load(pagesLibrary, pagesLibrary => pagesLibrary.RootFolder.Files);
cc.ExecuteQuery();
ListItem newClientPage = pagesLibrary.RootFolder.Files.AddTemplateFile
cc.Web.ServerRelativeUrl + "/SitePages/KnowledgeJunction.aspx",
TemplateFileType.ClientSidePage).ListItemAllFields;
newClientPage["ClientSideApplicationId"] = "<GUID>";
newClientPage.Update();
cc.Load(newClientPage);
cc.ExecuteQuery();
We could set other properties as well like => ContentTypeId, Title, PageLayoutType, PromotedState, BannerImageUrl and so on…
code for getSitePagesLibrary() method
private static List getSitePagesLibrary(string siteUrl, ClientContext contentContext)
{
List sitePagesLibrary = null;
try
{
Web web = contentContext.Web;
contentContext.Load(web, w => w.ServerRelativeUrl, w => w.Lists);
contentContext.ExecuteQuery();
string listURL = web.ServerRelativeUrl + "/SitePages/";
sitePagesLibrary = web.GetList(listURL);
contentContext.Load(sitePagesLibrary);
contentContext.ExecuteQuery();
}
catch (Exception ex)
{
//ToDO: Logging
}
return sitePagesLibrary;
}//getSitePagesLibrary
Thanks for reading 🙂 Feel free to discuss / comments / questions 🙂 SHARING IS CARING 🙂
Share In Teams:Enjoy the beautiful life 🙂 Have a FUN 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂
2 Responses
[…] M365 – SharePoint Online – Resolving exception “NoComponentId” while creating new client sid… […]
[…] M365 – SharePoint Online – Resolving exception “NoComponentId” while creating new client sid… […]
You must log in to post a comment.