Modern Page Migration – Tenant to Tenant in O365

Traditionally, SharePoint sites have pages composed of multiple webpart zones and webparts in them. If you wanted to interact with a webpart you needed to do the following:

  1. Get the reference of the page
  2. Get hold of Webpart Manager
  3. Using Webpart Manager get hold of the webpart
  4. Make changes to the webpart or extract data from it.
With Modern Team sites, modern pages are built differently. Modern pages now have a control called CanvasControl which has all the webparts into it. With SharePoint PnP, it has been easier than ever to interact with SharePoint object.

Here is the hierarchy:

  1. Pages are called ClientSidePage
  2. Each Client Side Page has Canvas Section
  3. Each Section has Canvas Column
  4. Section and Column host multiple Canvas Controls (CanvasControl)
  5. Canvas Controls are of 2 types:
    1. ClientSideText
    2. ClientSideWebpart

Therefore, new modern pages are completely different than the traditional SharePoint pages. To migrate a Modern Page from a O365 tenant to another we need to deal with ClientSidePage and CanvasControl classes. But SharePoint page is not just a page with some data but there are other things attached to it. For example:

  1. Page Layout
  2. Page metadata e.g. Author, Editor, etc.
  3. Permissions – if the page has unique permissions

Hence, to migrate a page we need to take care of all these items into consideration too. Having said that, getting page content is easier now. To get the content of the entire page you can do the following:

  • Get the reference of the Client Side page
    1.  var newClientSidePage = targetWeb.AddClientSidePage(pageName, true); OR

    2. var sourcePage = ClientSidePage.Load(sourceContext, pageName);
  • Get Page List Item reference from the Client Side page.

        var clientSidePageItem = newClientSidePage.PageListItem;

  • Now we have the source page list item and target page list item objects. By taking the JSON data from source item and putting into the target item will do the job of transferring the source page content into the target page:

       targetItem[CanvasContent1] = sourceItem[“CanvasContent1];

  • Then set the values of PageLayoutType, which can be Home, Article, Wiki or Repost.

Once you have the page created in the target site with all the data that the source page has, other tasks (permissions and metadata migration) can be accomplished easily. You can check out my project at GitHub at this location.

If you liked the article, share it with your friends and colleagues. You can also send a “Thank you” note by buying me a coffee. Buy Me a Coffee

Leave a Comment

Your email address will not be published. Required fields are marked *