ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SharePoint 开发:如何将Classic Page 转换成Modern Page?

2021-06-03 16:04:11  阅读:280  来源: 互联网

标签:Modern Classic pages SharePoint Page Write Pages page


Blog链接:https://blog.51cto.com/13969817 

越来越多的企业希望将数据从legacy 的SharePoint平台迁移到SharePoint Online,因为这样用户可以使用Modern UI,访问数据时界面可以随着屏幕 size而自动调整页面布局,但最近跟韩国一个Partner讨论数据迁移后,Page UI无法convert成Modern UI的问题,如何向客户解释和排查原因?

客户源端环境是SharePoint 2013 Server,但Site Collection 的默认home page是default.aspx, 所以home page的URL类似: site collection URL/default.aspx, SharePoint 2013 Server新建的Site Collection home page URL不符。

排查问题:

·       我们使用SharePoint Designer访问了该Site Collection,发现default.aspx 存储在site的root folder中,而对比其他Site Collection, home page是存储在Site Pages library中。

·       查找了下相关资料,default page是使用在SharePoint 2003和SharePoint 2007的环境中,在SharePoint 2010时该种类型的page已经hidden了,新建Site Collection的default home page URL 类似:URL/SitePages/Home.aspx

解决方案:

如大家所掌握的,SharePoint Classic Page包含Wiki Pages, Web Part Pages, Blog Pages, Publishing Page, Web Page和Basic Page以及从低版本升级的default page:

·       目前无论是微软的Powershell还是.net客制化开发,仅支持Wiki Pages, Web Part Pages, Blog Pages, Publishing Page四种类型的Page从Classic Page转换为Modern Page;

·       其他Page,比如Default Page,我们可以在welcome page中将default page link替换为home page link,重新insert 相关的Web part。

下方是采用PowerShell convert pages的脚本示例,仅供参考:

<# 
.Synopsis
    Converts all classic wiki and web part pages in a site. 
    You need to install PnP PowerShell: https://pnp.github.io/powershell/
    Sample includes:
        - Conversion of wiki and web part pages
        - Connecting to MFA or supplying credentials
        - Includes Logging to File, log flushing into single log file       
.Example
    Convert-WikiAndWebPartPages.ps1 -SourceUrl "https://contoso.sharepoint.com/sites/classicteamsite" -TakeSourcePageName:$true
.Notes
    Useful references:
        - https://aka.ms/sppnp-pagetransformation
        - https://aka.ms/sppnp-powershell
#> 
[CmdletBinding()]
param (
    [Parameter(Mandatory = $true, HelpMessage = "Url of the site containing the pages to modernize")]
    [string]$SourceUrl,
    [Parameter(Mandatory = $false, HelpMessage = "Modern page takes source page name")]
    [bool]$TakeSourcePageName = $false,    
    [Parameter(Mandatory = $false, HelpMessage = "Supply credentials for multiple runs/sites")]
    [PSCredential]$Credentials,
    [Parameter(Mandatory = $false, HelpMessage = "Specify log file location, defaults to the same folder as the script is in")]
    [string]$LogOutputFolder = $(Get-Location)
)
begin
{
    Write-Host "Connecting to " $SourceUrl
    if($Credentials)
    {
        Connect-PnPOnline -Url $SourceUrl -Credentials $Credentials
        Start-Sleep -s 3
    }
    else
    {
        Connect-PnPOnline -Url $sourceUrl -Interactive
        Start-Sleep -s 3
    }
}
process 
{    
    Write-Host "Ensure the modern page feature is enabled..." -ForegroundColor Green
    Enable-PnPFeature -Identity "B6917CB1-93A0-4B97-A84D-7CF49975D4EC" -Scope Web -Force
    Write-Host "Modernizing wiki and web part pages..." -ForegroundColor Green
    # Get all the pages in the site pages library. 
    # Use paging (-PageSize parameter) to ensure the query works when there are more than 5000 items in the list
    $pages = Get-PnPListItem -List sitepages -PageSize 500
    Write-Host "Pages are fetched, let's start the modernization..." -ForegroundColor Green
    Foreach($page in $pages)
    { 
        $pageName = $page.FieldValues["FileLeafRef"]
        if ($page.FieldValues["ClientSideApplicationId"] -eq "b6917cb1-93a0-4b97-a84d-7cf49975d4ec" ) 
        { 
            Write-Host "Page " $page.FieldValues["FileLeafRef"] " is modern, no need to modernize it again" -ForegroundColor Yellow
        } 
        else 
        {
            Write-Host "Processing page $($pageName)" -ForegroundColor Cyan
            # -TakeSourcePageName:
            # The old pages will be renamed to Previous_<pagename>.aspx. If you want to 
            # keep the old page names as is then set the TakeSourcePageName to $false. 
            # You then will see the new modern page be named Migrated_<pagename>.aspx
            # -Overwrite:
            # Overwrites the target page (needed if you run the modernization multiple times)
            # -LogVerbose:
            # Add this switch to enable verbose logging if you want more details logged
            # KeepPageCreationModificationInformation:
            # Give the newly created page the same page author/editor/created/modified information 
            # as the original page. Remove this switch if you don't like that
            # -CopyPageMetadata:
            # Copies metadata of the original page to the created modern page. Remove this
            # switch if you don't want to copy the page metadata
            ConvertTo-PnPPage -Identity $page.FieldValues["ID"] `
                                -Overwrite `
                                -TakeSourcePageName:$TakeSourcePageName `
                                -LogType File `
                                -LogFolder $LogOutputFolder `
                                -LogSkipFlush `
                                -KeepPageCreationModificationInformation `
                                -CopyPageMetadata
        }
    }
    # Write the logs to the folder
    Write-Host "Writing the conversion log file..." -ForegroundColor Green
    Save-PnPPageConversionLog
    Write-Host "Wiki and web part page modernization complete! :)" -ForegroundColor Green
}
end
{
    Disconnect-PnPOnline
}

相关资料:

·       Transform Classic Pages to Modern Pages

·       Transforming to modern site pages using Powershell

谢谢大家阅读,将遇到的问题,整理分享出来,希望日后能帮助到大家。


标签:Modern,Classic,pages,SharePoint,Page,Write,Pages,page
来源: https://blog.51cto.com/u_13969817/2852036

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有