In this blog, I am going to perform two actions –

  1. Identify if a page is a modern page or not.
  2. Migrate or copy that modern page (including its content) to another site collection or site (destination location)

I am going to accomplish these tasks by using CSOM (Client Object Model). After identifying the modern page, I will copy the modern page into another site collection (destination location) and then, will migrate all the page contents of this modern page (including web parts and other properties of source modern page) to a destination web using CSOM.

We are using a console application to achieve the above functionality using CSOM. In the below-mentioned code logic, we will get all pages from ‘Site Pages’ page library which is present in the source web and looping each page to check if that is a modern page or not.

If the page is found to be a modern page, then we are migrating that page to the destination web ‘Site Pages’ library.

Please have a look at the below code. The code is self-explanatory because of the comments.
Destination Page Library Before Migration,
Destination Page Library after Migration

After executing the above code behind, you can find the newly created modern page in the destination web ‘Site Pages’ library with the same page contents and “web parts” as they were in the source page.