Try our conversational search powered by Generative AI!

Set the parent of an existing page type programmatically


Hi, I want to move a page type under another one. So I tried to change the parent Link as:

productPageType.ParentLink = pageType.ContentLink.ToPageReference();


The problem is after running the script, I see my page was not moved. 

Can you help me?

Thank you

Edited, Aug 08, 2017 8:31
ServiceLocator.Current.GetInstance<IContentRepository>().Move(sourceRef, targetRef, ..)
Aug 08, 2017 8:45

Hello Valdis,

Great this work.

I have another question, if possible to set the position/order where the item should be moved in the hieraquicy?

Thank you

Aug 08, 2017 9:00

As far as I remember (no compilation done):

var repo = ServiceLocator.Current.GetInstance<IContentRepository>();
var newVersion = page.CreateWritableClone();
newVersion.Property[MetaDataProperties.PagePeerOrder].Value = defaultSortOrder;

Aug 08, 2017 9:30

aaaand.... `ServiceLocator` is BAD! :)

use proper dependency injection.

Aug 08, 2017 9:31
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.