0

I have many Pages in SharePoint Online, with modern text editor having many document links pointing to Document library within same Site Collection. Now we are planning to move documents into multiple document library based on some classification. Hence we want to update the existing URL with new URL. Is there a way to update links without editing each page manually and update?

Here is an example of a page

enter image description here

1 Answer 1

0

You could possibly have considered using Document IDs so URLs to documents are kept even when moved to another library or site.

https://support.microsoft.com/en-us/office/activate-and-configure-document-ids-in-a-site-collection-66345c77-f079-4104-ac7a-e25826849306?ocmsassetid=ha102773259&correlationid=5a81a8b7-0220-4602-8f89-61efa7bd5744&ui=en-us&rs=en-us&ad=us

However, assuming you haven't done so, you can use PnP.PowerShell to build a script that iterates SharePoint Online site pages.

https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets

# define which site collection you want to run the script on
$siteCollectionUrl = ""

# replacement hastable where the key is the old document url and the value is the new document url
$replacementlist = @{"https://olddocumenturl" = "https://newdocumenturl"}

# Connect to SharePoint site
Connect-PnPOnline -Url $siteCollectionUrl -Interactive

# Get list items
$pages = Get-PnPListItem -List "Site Pages" 

# Iterate list items
foreach($page in $pages) {
   # do work
}

On every page you must iterate the page controls and look for the PageText type, and then some additional logic to replace the actual URLs before saving and re-publishing the page.

Hopefully this is helpful and can get you started.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.