Skip to content

Commit 2917458

Browse files
committed
Documentation of direct page transformation from on-premises
1 parent f1b245d commit 2917458

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

docs/transform/modernize-userinterface-site-pages-dotnet.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,63 @@ using (var cc = am.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userNa
153153
> [!Note]
154154
> Not all web parts lend themselves well for a cross site transfer, check the **Cross site support** column in [web part transformation list](modernize-userinterface-site-pages-webparts.md) to learn more.
155155
156+
157+
### Read publishing page in on-premises SharePoint and create the modern page in SharePoint Online (as of June 2019 release, version 1.0.1906.*)
158+
159+
When you want to bring over your classic on-premises publishing portals you could first move the complete portal from on-premises to a classic portal in SharePoint Online and then do the modernization work. However, often it's easier to directly read the classic publishing page from your SharePoint on-premises portal and create the modern version in SharePoint Online.
160+
161+
```csharp
162+
string siteUrl = "https://sp.contoso.com/sites/myonpremisesportal";
163+
string targetSiteUrl = "https://contoso.sharepoint.com/sites/mycommunicationsite";
164+
string userName = "[email protected]";
165+
AuthenticationManager am = new AuthenticationManager();
166+
167+
// Setup on-premises client context
168+
using (var cc = new ClientContext(siteUrl))
169+
{
170+
cc.Credentials = CredentialCache.DefaultCredentials;
171+
172+
// Setup SharePoint Online context
173+
using (var ccTarget = am.GetSharePointOnlineAuthenticatedContextTenant(targetSiteUrl, userName, GetSecureString("Password")))
174+
{
175+
var pageTransformator = new PublishingPageTransformator(cc, ccTarget, "C:\\temp\\custompagelayoutmapping.xml");
176+
177+
// Register the log observers
178+
pageTransformator.RegisterObserver(new MarkdownObserver(folder: "c:\\temp", includeVerbose:true));
179+
pageTransformator.RegisterObserver(new MarkdownToSharePointObserver(ccTarget, includeVerbose: true));
180+
181+
var pages = cc.Web.GetPagesFromList("Pages", "a");
182+
foreach (var page in pages)
183+
{
184+
PublishingPageTransformationInformation pti = new PublishingPageTransformationInformation(page)
185+
{
186+
// If target page exists, then overwrite it
187+
Overwrite = true,
188+
};
189+
190+
try
191+
{
192+
Console.WriteLine($"Transforming publishing page {page.FieldValues["FileLeafRef"]}");
193+
pageTransformator.Transform(pti);
194+
}
195+
catch(ArgumentException ex)
196+
{
197+
Console.WriteLine($"Page {page.FieldValues["FileLeafRef"]} could not be transformed: {ex.Message}");
198+
}
199+
}
200+
201+
// Flush the log data
202+
pageTransformator.FlushObservers();
203+
}
204+
}
205+
```
206+
207+
> [!NOTE]
208+
> - This feature is still in preview in the June 2019 release...it should support SharePoint 2013, 2016 and 2019
209+
> - It's important to run your code on a machine that is able to connect to both the on-premises SharePoint server as the SharePoint Online environment
210+
> - There (currently) is no user mapping feature, hence item level permissions are not copied over from the on-premises publishing page to the SharePoint Online modern page
211+
> - This approach can also be used for page transformation across tenants (whenever that would make sense)
212+
156213
### I want to use the logging features (as of April 2019 release, version 1.0.1904.*)
157214

158215
By default there are three possible log observers (Console, Markdown and MarkdownToSharePoint). The latter two create an MD based report and put them on disk or in SharePoint as a client side page, whereas the first one simply outputs console messages. Below sample shows how you can use the loggers from .Net:

docs/transform/modernize-userinterface-site-pages-powershell.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/portaltomodernize
9797
ConvertTo-PnPClientSidePage -PublishingPage -Identity mypage.aspx -Overwrite -TargetWebUrl https://contoso.sharepoint.com/sites/moderncommunicationsite -PageLayoutMapping c:\temp\mypagelayouts.xml
9898
```
9999

100+
### Read publishing page in on-premises SharePoint and create the modern page in SharePoint Online (as of June 2019 release, version 3.10.1906.*)
101+
102+
When you want to bring over your classic on-premises publishing portals you could first move the complete portal from on-premises to a classic portal in SharePoint Online and then do the modernization work. However, often it's easier to directly read the classic publishing page from your SharePoint on-premises portal and create the modern version in SharePoint Online. To do this you need to use PnP PowerShell for SharePoint Online to connect to your on-premises portal like shown in below script:
103+
104+
```Powershell
105+
# Setup connection the target site - must be SPO and must be a modern site
106+
$target = Connect-PnPOnline https://contoso.sharepoint.com/sites/moderncommunicationsite -ReturnConnection
107+
108+
# Connect to your on-premises portal
109+
Connect-PnPOnline https://portal2013.pnp.com/sites/classicportal -CurrentCredentials
110+
111+
# Convert a classic page living in the on-premises portal to a modern page in SharePoint Online. Dependent images and videos are copied as well from on-premises to online during this process.
112+
ConvertTo-PnPClientSidePage -Identity "page1.aspx" -PublishingPage -TargetConnection $target -LogVerbose -LogType File -LogFolder c:\temp
113+
```
114+
115+
> [!NOTE]
116+
> - This feature is still in preview in the June 2019 release...it should support SharePoint 2013, 2016 and 2019
117+
> - It's important to use the SharePoint Online PnP PowerShell version, the machine running the PowerShell script needs to be able to connect to both the on-premises SharePoint server as the SharePoint Online environment
118+
> - There (currently) is no user mapping feature, hence item level permissions are not copied over from the on-premises publishing page to the SharePoint Online modern page
119+
> - This approach can also be used for page transformation across tenants (whenever that would make sense)
120+
100121
### Use the logging features (as of June 2019 release, version 3.10.1906.*)
101122

102123
```Powershell

0 commit comments

Comments
 (0)