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: