I'm trying to migrate customized webpart data from onpremise to online in Content Editor webpart.
I'm copying the contents of the webpart from onpremise and creating a new content editor in the Sharepoint online and updating the contents of onpremise webpart.
Below code successfully fetched the text data but not pictures or hyperlinks.
function GetListOfWebpartDetails($SourceUrl, $TargetUrl) {
Write-Host “Source url: $($SourceUrl)...." -ForegroundColor Green
Connect-PnPOnline $SourceUrl -UseWebLogin
$context = Get-PnPContext
$site = $context.Web
$context.Load($site)
$context.ExecuteQuery()
$items = Get-PnPListItem -List sitepages -PageSize 500
if ($items) {
foreach ($pages in $items) {
$pageName = $pages.FieldValues["FileLeafRef"]
$PageUrl = "$($Site.SiteUrl)/SitePages/$pageName"
$lineArr = $PageUrl.Split(".")
if ($lineArr[1]) {
if ($lineArr[1].ToUpper().Contains('aspx'.ToUpper())) {
Connect-PnPOnline $SourceUrl -UseWebLogin
$WebPartManager = Get-PnPWebPart -ServerRelativePageUrl $PageUrl
#Get All Web Parts data
foreach ($WebPart in $WebPartManager) {
if ($WebPart.WebPart.Title.ToUpper().Contains('Test'.ToUpper())) {
write-Host $($WebPart.WebPart.Title)
$webpartProps = $webpart.WebPart.Properties.FieldValues
foreach ($webpartProp in $webpartProps) {
Write-Host "Content : " $webpartProp["Content"]
}
Write-Host "-------------------------------------------"
$targetPageURL = $target_site.ServerRelativeUrl + $PageUrl
$targetcontent = $webpartProp["Content"]
$zoneid = Get-PnPProperty -ClientObject $webPart -Property ZoneId
#Adding Content Editor Webpart XML in $WebXml
$WebXml = "<WebPart xmlns='http://schemas.microsoft.com/WebPart/v2' xmlns:iwp='http://schemas.microsoft.com/WebPart/v2/ContentEditor'>
<Title>$($WebPart.WebPart.Title)</Title>
<FrameType>None</FrameType>
<Description>$($webpartProp["Description"])</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>$zoneid</ZoneID>
<PartOrder>0</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>true</AllowConnect>
<AllowEdit>true</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge>/_layouts/15/images/mscontl.gif</PartImageLarge>
<IsIncludedFilter />
<Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
<Content xmlns='http://schemas.microsoft.com/WebPart/v2/ContentEditor'>$targetcontent</Content>
<PartStorage xmlns='http://schemas.microsoft.com/WebPart/v2/ContentEditor' />
</WebPart>"
Write-Host "Target url: $($TargetUrl)...." -ForegroundColor Green
Connect-PnPOnline $TargetUrl -UseWebLogin
try {
Add-PnPWebPartToWikiPage -ServerRelativePageUrl $targetPageURL -XML $WebXml -Row 1 -Column 1
Write-Host "Migrated Webparts Succesfully"
}
catch {
Write-Host "Page not found/Errors found:`n$_" -ForegroundColor Red
}
}
}
}
}
}
}
}
Appreciate if anyone can provide any lead.