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.
10,946 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.
3,119 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 36,651 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.


  2. Ana 0 Reputation points
    2024-11-25T11:41:33.4633333+00:00

    Hi,

    Any news on this issue? I'm converting HTML to ASPX but now I can't open the file.

    Thanks,

    Ana

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.