How do you programmatically rename a page?

Vote:
 

I am using the IContentRepository to copy an existing page programatically, and then creating a writable clone to modify the newly copied page's fields.

One thing I am looking at doing is renaming the page.  When I update the "Name" property, I see that this is now reflected within the Epi Edit interface on the property panel.  However, the page is not renamed within the Page Hierarchy.

What is the proper way to rename a page programatically?

#226566
Aug 14, 2020 19:27
Vote:
 

Hi Dylan

The proper way is to create a clone, change the Name property and publish the changes.

Did you remember to publish while saving the changes? If not, you will only see the Name changed in the editor view, not in the tree view.

#226589
Aug 15, 2020 8:37
Vote:
 

Hi Dylan,

After creating a clone change the name of the page and publish it programmatically:

var repo = ServiceLocator.Current.GetInstance<IContentRepository>();
repo.Save(newPage, EPiServer.DataAccess.SaveAction.Publish, AccessLevel.NoAccess);
#226610
Edited, Aug 16, 2020 2:27
Vote:
 

If you would like to update the url segment, you must also update this property:

newPage.URLSegment = "new-url-segment";
#226643
Edited, Aug 17, 2020 8:16
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.