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

M365 - SharePoint Online - Exception "NoComponentId" while creating new client side page in Site Pages Library using CSOM
M365 - SharePoint Online - 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:

M365 - SharePoint Online - Exception "NoComponentID" while creating new client side page in Site Pages Library
Fig : M365 – SharePoint Online – Exception “NoComponentID” while creating new client side page in Site Pages Library using CSOM

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 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

2 Responses

  1. February 5, 2021

    […] M365 – SharePoint Online – Resolving exception “NoComponentId” while creating new client sid… […]

  2. February 15, 2021

    […] M365 – SharePoint Online – Resolving exception “NoComponentId” while creating new client sid… […]

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: