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

Forums / Developing with Sitefinity / Controlling the order that content is returned

Controlling the order that content is returned

3 posts, 1 answered
  1. Kaine Varley
    Kaine Varley avatar
    13 posts
    Registered:
    25 Aug 2009
    17 Mar 2010
    Link to this post
    Hi,

    Building on my previous post (Is there a difference in the ways that the content is returned?), for events I am using the following (the code has been simplified for illustration):

    ContentManager contentMan = new ContentManager("Events");
    foreach (IContent itemContent in contentMan.GetContent(0, 10, "[Start] ASC"))
    {
      // Get the start date.
      DateTime startDate = DateTime.Parse(itemContent.GetMetaData("Event_Start"));
    }


    However, the content is being returned in, what appears to be, random order (although I suspect that it is the order that it was created). Is there a way that I can get the content to return in the correct order, or do I have to use the EventsManager to achieve this?

    I have simplified the code since it is fairly generic and shared between other content items such as News items.

    When retrieving content in this way, what order is the content returned in by default and what Sort Expressions can be used?

    Thanks,


    Kaine
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    17 Mar 2010
    Link to this post
    Hi Kaine Varley,

    Sort Expression parameter can be used only for metakeys.

    sample

    IList items = contentMan.GetContent(0, 10, "Event_Start ASC");

    The items in the list above should be sorted in ascending order. You can use ASC or DESC. The same apply for all IContent objects. Additionally you can sort the list using LINQ by a property parameter.


    Kind regards,
    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.
    Answered
  3. Kaine Varley
    Kaine Varley avatar
    13 posts
    Registered:
    25 Aug 2009
    17 Mar 2010
    Link to this post
    Thanks Ivan,

    I used the Finding Events article as a template for my solution, but, after seeing your suggestion, it seems pretty obvious.

    Thanks again,


    Kaine
Register for webinar
3 posts, 1 answered