+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Displaying latest version of published content

Displaying latest version of published content

6 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Nov 2010
    Link to this post
    Hi,

    I have a module that has workflow enabled. On the public website I need to be able to display all content that is either published, or if it is awaiting approval show the version that was previously published - i.e. if version 2 is Awaiting approval, show version 1.

    This is exactly the same as the behaviour for listings like news and events.

    How do i acheive this? I expected ContentManager.GetContent to do this, but it doesnt - it gets the latest version of all content even if it is still awaiting approval.

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Nov 2010
    Link to this post
    Hi higgsy,

    Below is a sample code that illustrate how to retrieve a content with a given workflow status

    protected override void OnLoad(EventArgs e)
    {
        
          
        var newsManager = new ContentManager("News");
     
        IList listofAllItems = newsManager.GetContent();
        List<IContent> itemsForApproval = new List<IContent>();
        foreach (IContent cnt in listofAllItems)
        {
            StagedContent stagedCnt = newsManager.GetCurrentState(cnt.ID);
            if (stagedCnt !=null && stagedCnt.WorkflowInstanceId != Guid.Empty)
            {
                WorkflowInstance workflow = WorkflowRuntime.Instance.GetWorkflow(stagedCnt.WorkflowInstanceId);
                if (stagedCnt != null && workflow != null)
                {
     
                    ContentWorkflow contentWorkflow = (ContentWorkflow)workflow.Activity;
                    if (contentWorkflow.ApprovalStatus == ApprovalStatus.ForApproval)
                    {
     
                        itemsForApproval.Add(cnt);
                       
     
                    }
                }
            }
        }
      
    }


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Nov 2010
    Link to this post
    Hi Ivan,

    That won't really do the job. If i include items that are WaitingApproval then I will be displaying items that aren't actually approved.

    If a content item has two versions:

    Version 1 - Published
    Version 2 - Awaiting Approval

    I need to display version 1 i.e. the last published version.

    If a news article is on the website, and then a content editor updates it and sends it to an administrator for approval, the news article doesnt dissapear from the website - it continues to show the latest published version until the new version has been approved. That is exactly what i need to replicate.

    Could you provide some more infromation on that please.

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    25 Nov 2010
    Link to this post
    Hello higgsy,

    1. Get Content returns the last published version.
    2. To show the the version that was previously published you need to use VersionManager. You will find some samples here.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Nov 2010
    Link to this post
    Hi Ivan,

    Ok, i'm making progress. I am able to get all of the versions of a generic content item, but how can I compare the versions to check which one was the latest "published" item, because that is not always the previous version.

    VersionManager oVersionMgr = new VersionManager();
    IList oItems = oVersionMgr.GetItems(oContentItem.ID, System.Globalization.CultureInfo.InvariantCulture);
     
    foreach (IVersionItem oItem in oItems) {

           // how can I tell which was the version that was most recently published? 
     
    }

    As an example:

    1) I create a content item.
    2) Content item is approved - version 1.
    3) I update the content item - version 2 is sent for approval.
    4) Before an administrator has approved version 2, i update the content item to create version 3.

    In this scenario I need to be able to get hold of version 1, but obviously programmatically I need to be able to check that version N was the most recently published item.

    Thanks
    higgsy
  6. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    25 Nov 2010
    Link to this post
    Hi Ivan,

    What do you suggest to resolve this?

    Regards,
    higgsy
Register for webinar
6 posts, 0 answered