Convert html files to aspx in SharePoint Online

Alexandre 20 Reputation points
2023-01-23T07:21:41.2066667+00:00

Hi Community,

I have a site collection in SharePoint Online containing multiple htm/html files. In these files, I have links to other htm/html files (href in anchor tags for example).

I would like to convert all these files to aspx and automatically update my internal links too. It looks like it is possible according to this article: https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-permissivesetting 

By following this documentation, the renaming process works well but my internal links are not updated. If I understand well this specific section=> https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-permissivesetting#what-about-htmlhtml-files-referenced-in-a-content-editor-web-part, it should be done automatically but it does not work... My internal links remain htm.

I did a quick test in CSOM to use explicitly MoveTo api as well =>

$File = $Ctx.Web.GetFileByServerRelativeUrl($OldFileURL)

$File.MoveTo($NewFileURL, [Microsoft.SharePoint.Client.MoveOperations]::Overwrite)

$Ctx.ExecuteQuery()

Same result, files are renamed but not internal links.

Would you have any idea? Or have you already done such kind of process sucessfully?

Thanks a lot!

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,135 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,546 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 29,031 Reputation points Microsoft Vendor
    2023-01-23T09:18:36.05+00:00

    Hi @Alexandre

    You can run following script to rename the files in sharepoint

    Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/sitename  -Credentials (Get-Credential)
    $listitems = Get-PnPListItem -List "Your list name"
    
    foreach ($item in $listitems) {
      Write-Output "Processing item $($item.ID)"
      $item["Title"] = $item["FileLeafRef"]
      $item["FileLeafRef"] = $item["Code"]
      $item.Update() 
    }
    Invoke-PnPQuery
    Disconnect-PnPOnline
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.