Copying a page from one site to another in SharePoint

In this post we look at three different ways you can copy a page from one SharePoint site to another

In this post we look at three different ways you can copy a page from one SharePoint site to another.

Intro

The copy/ move features within SharePoint Online were introduced a few years ago, and although they are pretty good, aren’t without their limitations – something I wrote about in 2021. One such limitation is the inability to be able to copy or move site pages from one SharePoint site to another – a frequent request of users and of the SharePoint community to Microsoft, but so far nothing has been implemented.

I’m going to cover a few ways you can copy a site page from site to site, using a variety of different tools and products along the way.

#1 Create a flow in Power Automate

In this example we can use Power Automate to allow users to select the page they want to copy, input the site URL they want to copy to and let the flow do its magic!

  • Create a new flow in Power Automate > use the instant cloud flow option.
  • Create a for a selected file trigger > enter the site address and library name.

NOTE: In my example, just entering ‘Site Pages’ resulting in my flow not appearing in the Site Pages library. This seems to be an issue with the for a selected file trigger. In order to get it to show up, I had to use the library ID instead of the library name. To get the library ID:

  • Open the library settings > more library settings
  • Copy everything between List=&7B until %7D – this is the library ID
Copy the library ID which is the numbers between &7B and %7D
  • In the for a selected file trigger > add an input
  • Select text as the user input type > update the input name and input value placeholder text. This user input type will be used to allow users to enter the site URL they wish to copy their pages to.
Add a text user input type to allow users to input the destination site URL.
  • Add a get file properties action and configure with the following:
    • Enter the source site address of your site pages library
    • Enter either site pages, or the ID of your site pages library
    • Under ID > select ID from the for a selected file trigger
  • Add a copy file action and configure with the following:
    • Current site address: source site address of your site pages library
    • File to copy: Identifier from get file properties
    • Destination site address: destination site (or whatever you called your user input) from for a selected file
    • Destination folder: /SitePages
    • If another file is already there: copy with a new name (optional)

Three steps – that’s it! Now go ahead and test your flow by selecting a site page and copying it to a different site by running your flow.

#2 Use PnP PowerShell

Another way you are able to do this is with PowerShell, in this case I’ll defer to the brilliant SharePoint diary who has a great write up, including all cmdlets you need to copy a page from site to site, or copy all pages. I’ll include the relevant sample for my blog post, but full credit goes to SharePoint diary:

#Parameters
$SourceSiteURL = "https://crescent.sharepoint.com/sites/marketing"
$DestinationSiteURL = "https://crescent.sharepoint.com/sites/branding"
$PageName =  "About.aspx"
 
#Connect to Source Site
Connect-PnPOnline -Url $SourceSiteURL -Interactive
 
#Export the Source page
$TempFile = [System.IO.Path]::GetTempFileName()
Export-PnPPage -Force -Identity $PageName -Out $TempFile
 
#Import the page to the destination site
Connect-PnPOnline -Url $DestinationSiteURL -Interactive
Invoke-PnPSiteTemplate -Path $TempFile

Click here for the full artcle from SharePoint diary.

#3 Use 3rd party migration tools

The final option we have available to us is to utilize 3rd party migration tools to migrate pages between sites. For this example I’ll be using ShareGate, but there are other migration tools that are able to do the same thing:

  • Open ShareGate desktop > press copy.
  • Select copy content only.
  • Enter the URL of your source site > select the Site Pages library.
  • Do the same for the destination site.
  • Select the page from the source location you wish to copy
  • Under options, make the following configuration changes:
    • Check preserve authors and time stamps
    • Check permissions
    • Uncheck user alerts
    • Check web parts
    • Check version history
    • Uncheck flatten folder hierarchy
    • Check update links
    • Check check in as = published
  • Press start copy. Once completed, you should see two successful migration task items for your copied page:

Now you will find your newly copied page in the destination Site Pages library. In my experience of copying pages using ShareGate, images hosted within a CDN will still be present within your page, as will all the of text, layouts and any formatting. Images that are stored within different sites may error, as will document library/ list web parts that point to different sites also.


29 responses to “Copying a page from one site to another in SharePoint”

  1. Thank you SO MUCH. Really a lifesafer. Solved my issue in a second. Beautiful stuff man!

  2. Thank you so much the PA flow. Could you please confirm this can work to copy pages between two different SP tenant?
    I get a 400 error Invalid URL, while the destination URL is fine…

    1. Hi Tanguy, I haven’t tried it across tenants, but I would assume the answer is no as you will only be able to create connections to SharePoint against the tenancy the flow is running in – I think!

      1. That’s what I thought. Too bad.
        Thanks anyway for your guidance, very instructive!

  3. Hi Anthony,

    I am unable to locate the ‘Library’ in the below step to able to get the library settings. Where is the library located in my SharePoint?

    Open the library settings > more library settings
    Copy everything between List=&7B until %7D – this is the library ID

    1. Hi Claudia, thanks for the comment. This should be the Site Pages library, which you can find by pressing the cog > site contents > select Site Pages.

      Hope this helps!
      Cheers,
      Anthony

  4. Hey Anthony,
    great post, unfortunately I have not been able to get it to work, I get the following error message on the Copy file step:

    {
    “status”: 400,
    “message”: “Failed to verify the existence of source object at ‘https://XXXXXX.sharepoint.com/sites/Test/3’ due to error ‘The system cannot find the file specified. (Exception from HRESULT: 0x80070002)’.\r\nclientRequestId: XXXXXXXXX\r\nserviceRequestId: XXXXXXXXXX”
    }

    I’ve tried tweaking the settings, but always seem to get the same result. Any suggestions would be greatly appreciated.

    1. Hi George, thanks for the comment. I’ve ran my test flow again now (for the first time in ages) and it’s still working for me. A few things to double-check:
      – What is “3”, is it a site page?
      – For the destination, are you just entering the site URL, without the destination library?

      1. I was wondering the same thing about the “3” on the end of the URL, it seems this changes based on the page I choose to copy, so maybe the ID attribute is pulling the incorrect information for me.

        I ended up playing around a bit more and created a slightly different, but pretty much the same, flow that removed the get file properties step.
        The steps I used the same steps as you:
        1. For selected file
        – Set Source site, same as outlined in your steps
        – I had the same issue as you, where I had to add the pages library via the string rather than the name for it to show up in the automate menu option
        – Added the same text input for destination site as outlined in your steps
        2. Copy file
        – Set source site same as outlined in your steps
        – For the “file to copy” field, I used “SitePages/[fileName]” attribute from the first step (“SitePages/” being typed manually as text in front of the attribute)
        – Set destination from the text input on step one, same as outlined in your steps

        This flow is now working for me. I really appreciate you actually replying to my comment and really found this article very helpful.

      2. How strange, I think you must of cracked it with the removal of the get files step though so good news!

    2. I had the same issue so leaving my workaround here.

      I added a Compose after the get files properties and got the Full Path of the item. I then used the Output in the File to Copy field. It’s not pretty but it works.

    3. Had the same issue. Used the “identifier” property instead of “ID” in “File to Copy” field in step 3. This worked for me

  5. The flow worked perfectly! Thank you 🙂

  6. This is excellent!! I had tried a different approach in Power Automate but got knocked back by ‘permission denied’. I’d assumed this was because you can’t add files into Site pages, only create new page (or url link) from the dropdown menu.

    An important step forward in terms of rolling out our intranet project as it will enable us to push templates to different sites within a hub. Thanks very much

  7. Fantastic! Power Automate worked for me. Thank you very much!

  8. Hi Anthony, Thanks for the information, building the flow was pretty simple with your instructions. One question I’m struggling with… when I select a site page, then automate, then power automate, I don’t see the name of my flow. Only options are “Create a flow”, “See your flows”, and “Configure page approval flow”. Is there an additional step I need to take in order for the flow to become an available option?

    1. Hi, it could be that the permissions to your flow haven’t been set to allow others to run as/ be owners. More info here https://powerusers.microsoft.com/t5/Using-Flows/Instant-Flow-not-visible-in-the-associated-List/td-p/921731

      1. Hi Anthony, I was the flow owner so permissions were ok. It turned out the flow had to be built in my personal productivity environment since it uses a SharePoint integrated function, these only work in PP environment. I was originally creating in the staging environment since my intent was to move site pages from staging to production. Figured it was worth sharing in case anyone else incurs this issue. Thanks again for your help! Great job!

      2. Hi GM, thank you for following up on this. Out of interest, would environment variables in a solution overcome the integrated function issue? Best Anthony

  9. Hi, could you be specific about Library Settings please? Which Library where? (I got as far as realising that Power Automate refers to Power Automate the app/application/program, and not the Power Automate function within SharePoint, so I am making progress as a novice).

    >use the library ID instead of the library name. To get the library ID:

    Open the library settings > more library settings

    1. Hi, sure you just need to get to the library settings page by pressing more library settings. This then adds the ID of the library to the URL, which you can then grab

  10. Superb! I’ve never used Power Automate before but I followed the instructions to create a Flow and it worked perfectly. Thank you, Anthony!

    Fairly obvious, perhaps, but I note that the value for “Desination Site” to write into the query box when you’ve started the Flow is the landing page URL of the SharePoint Site (i.e. the /SitePages part of the URL where the .aspx file will end up was already written into the Flow settings)

    1. Hi Allan, thank for you the comment and the additional information – much appreciated!

  11. this is awesome, worked !

    1. Thank you! Glad it helped

  12. I used the Power Automate method that you suggested and it worked perfectly! I also understand a lot more about creating flows now, as this was my first one. Thanks so much!

    1. Thank you!

  13. Thank You for the detailed explanation while using SPPMT am getting error Enable custom script setting which is already on . Please advise

    1. Thanks for the comment. Without seeing the error specifically, I would suggest running the PowerShell cmdlet provided in the article below to enable custom scripting on ‘other’ sites aswell https://learn.microsoft.com/en-us/sharepoint/allow-or-prevent-custom-script

Leave a Reply

Recent posts

Discover more from SharePoint Stuff

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

Continue reading