How to get the master version of the page programmically? (P

Posted by Community Admin on 04-Aug-2018 13:50

How to get the master version of the page programmically? (PageNode or PageData)

All Replies

Posted by Community Admin on 25-Aug-2015 00:00

The problem:

 I have a published PageNode and I want to edit its PageData. To be exact I want to access some of the page's widgets and change some values. I figured that all out and it at least seems to work.

 However, I use PageNode's GetPageData() -function to get the Pagedata and with that I get the Live version of the PageData and it seems that my changes get overrun when I republish the page.

We use the code:

 var bag = new Dictionary<string, string>();

 bag.Add("ContentType", typeof(PageNode).FullName);

WorkflowManager.MessageWorkflow(pageNode.Id, typeof(PageNode), null, status, false, bag);

 for publish operation because we sometimes also have to unpublish pages and this operation isn't supported by PageNode's ApprovalWorkflowStatus. But this overruns my changed Live PageData. Without running this publish the changes are visible in live site but not in page editor (since it probably uses Master version to create Draft?)

So want to get the Master version to edit and re-publish it.  Should be very simple scenario but to my amaizement it has been pretty hard. If I know the PageNode or Live PageData how can I access the Master version?!

 Tried a lot of different things but none seem to work, some methods return some strange PageDraft object and none of the stuff like this

 IQueryable<PageData> pages = pageManager.GetPageDataList().Where(pData => pData.Status == ContentLifecycleStatus.Master && pData.NavigationNodeId == pageNode.Id);

 seems to work, returns an empty list.

Posted by Community Admin on 28-Aug-2015 00:00

Hello,

You need to work with the PageDraft and modify it as it acts as the master. This blog post: Global Search and Replace in Sitefinity Content Blocks showcases how to do a global search and replace in content blocks and also uses the PageDraft and checks out the page to edit the content block and then publishes it.

Give this approach a try and get back to us if you have further questions.

Regards,
Atanas Valchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed