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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

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… […]

Leave a Reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading