Convert .html pages to .aspx

tipmat9 21 Reputation points
2020-11-13T18:38:54.857+00:00

We recently migrated from SharePoint On-Premises to SharePoint Online, most of the files in a Library are .html none of them works in browser after the migration when I click on a files it download automatically instead of opening them in browser, is there a way to convert all .html files in a library to .aspx ?

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,422 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,638 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sharath Kumar Aluri 3,071 Reputation points
    2020-11-13T19:02:00.327+00:00

    Below PowerShell Script should help your requirement:

    #Load SharePoint CSOM Assemblies
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
    
    #Config Parameters
    $SiteURL = "https://YourTenant.SharePoint.com/sites/sharatha"
    $ListName = "YourLibraryName"
    $BatchSize = 500
    
    #Setup Credentials to connect
    $Cred = Get-Credential
    $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    
    Try {
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Cred
    
        #Get the web and List
        $Web=$Ctx.Web
        $List=$web.Lists.GetByTitle($ListName)
        $Ctx.Load($List)
        $Ctx.ExecuteQuery()
        Write-host "Total Number of Items Found in the List:"$List.ItemCount
    
        $Query = New-Object Microsoft.SharePoint.Client.CamlQuery
        $Query.ViewXml = "<View Scope='RecursiveAll'><Query><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy></Query><RowLimit Paged='TRUE'>$BatchSize</RowLimit></View>"
    
        Do { 
            #Get items from the list in batches
            $ListItems = $List.GetItems($Query)
            $Ctx.Load($ListItems)
            $Ctx.ExecuteQuery()
    
            $Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition
            Write-host Renaming $($ListItems.count) Items Starting from Item ID $ListItems[0].ID
    
            #Loop through each file in the Library and Rename File(s) 
            foreach ($item in $ListItems)
            { 
            if($item.FileSystemObjectType -eq [Microsoft.SharePoint.Client.FileSystemObjectType ]::File) {  
            $destFileUrl = $item["FileRef"].ToString().Replace(".html",".aspx") 
            $item.File.MoveTo($destFileUrl, [Microsoft.SharePoint.Client.MoveOperations]::Overwrite) 
            $Ctx.ExecuteQuery() 
              } 
            }
            #$Ctx.ExecuteQuery()
    
            } While ($Query.ListItemCollectionPosition -ne $null)
    
            Write-host -f Green "All Items Renamed!"
    
        } Catch {
        write-host -f Red "Error Renaming List Items!" $_.Exception.Message
    }
    

    Thanks & Regards,

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.