How to get the master version of the page programmically? (PageNode or PageData)
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.
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