0

I need to create a page programmatically in a child folder under the Site Page library.

I have created an SPFx solution for the same. I have created a functional component and added one button on that button click event I need to create a page under a specific folder under the Site Pages library.

Also, I need to update the Description and Banner Image of that page programmatically.

I have used below pnp versions

  1. "@pnp/logging": "^3.12.1",

  2. "@pnp/sp": "^3.12.1",

Below is my code snippet,

const onButtonClick = () => {
      addPageToSitePages(state).then((res) => {
        console.log("page created....", res);
        loadSitePage(props.serverRelativeUrl + "/SitePages/" + encodeURI(state.Title) + ".aspx").then((res) => {
          console.log("page load....", res);
        }).catch((err) => {
          console.log("error....", err);
        });
      }).catch((err) => {
        console.log("error....", err);
      });
  };

export const addPageToSitePages = async (state: any) => {
    const sp: SPFI = getSP();
    // include title, page layout, and specifying the publishing status (Added in 2.0.4)
    const sitePage = await sp.web.addClientsidePage(state.Title, state.Title, "Article");
    console.log("sitePage", sitePage);
};

export const loadSitePage = async (sitePageUrl: any) => {
    const sp: SPFI = getSP();
    console.log("sitePageUrl", sitePageUrl);
    // our page instance
    const sitePage: IClientsidePage = await sp.web.loadClientsidePage(sitePageUrl);
    console.log("sitePage", sitePage);
    // get the current value
    const pageDescription = sitePage.description;
    console.log("pageDescription", pageDescription);
};

With the use of the above code,

  1. The page is created in the Site Page library instead of the child folder of the Site Page library. (I need to create the page in the child folder of Site Pages)
  2. I am unable to update the description of that newly created page.
  3. How can I update the BannerImage of that newly created page?

Can anyone help me with the above 3 points?

Thanks in Advance.

thedeepponkiya
  • 97
  • 1
  • 11

0 Answers0