Try Now
More in this section

Forums / Developing with Sitefinity / How to get the master version of the page programmically? (PageNode or PageData)

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

2 posts, 0 answered
  1. Arto
    Arto avatar
    6 posts
    10 Mar 2014
    25 Aug 2015
    Link to this post

    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.

  2. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    04 Jan 2016
    28 Aug 2015
    Link to this post

    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.

    Atanas Valchev
    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
2 posts, 0 answered