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

Forums / Developing with Sitefinity / How to retrieve blog posts sorted by DateCreated

How to retrieve blog posts sorted by DateCreated

4 posts, 0 answered
  1. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    20 Jul 2009
    Link to this post
    I can't seem to find a way to retrieve blog posts sorted by DateCreated field, this is a property of IContent and not defined in metadata so SortExpression doesn't find it. Any ideas?

            BlogManager manager = new BlogManager(); 
            Guid[] parentIDArray = new Guid[1]; 
            parentIDArray[0] = new Guid(HiddenItemId.Value); 
     
            List<IMetaSearchInfo> filter = new List<IMetaSearchInfo>(); 
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "Category""MyCategory")); 
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "IsPublic""Y")); 
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "FormType""", SearchCondition.NotEqual)); 
            filter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "WebUserId", WebUserLogin.User.UserID.ToString(), SearchCondition.NotEqual)); 
            IList contacts = manager.Content.GetContent(0, 0, "DateCreated"null, parentIDArray, filter.ToArray()); 
     

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Jul 2009
    Link to this post
    Hello Victor,

    It is not possible to use property to sort the items. You can use only metakeys. As a solution you can create a new metakey and use  o.SetMetaData("sdas", o.DateCreated);

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Victor
    Victor avatar
    44 posts
    Registered:
    10 Mar 2009
    21 Jul 2009
    Link to this post
    Thanks Ivan,

    I think it is a big oversight for such a CMS product to not have an easy way to retrieve posts sorted by date out-of-the-box, I hope this gets added in a future release.

    In the meantime I solved this by copying results to a generic list and sorting that with a delegate IComparer:

            IList contacts = manager.GetContent(0, 0, filter.ToArray(), parentIDArray); 
            List<IContent> blogs = new List<IContent>(); 
            foreach (IContent content in contacts) 
                blogs.Add(content); 
            blogs.Sort(delegate(IContent x, IContent y) { return x.DateCreated.CompareTo(y.DateCreated); }); 
     

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Jul 2009
    Link to this post
    Hello Victor,

    We will try to fix the issue for the forthcoming SP or in the next release.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered