Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Stephane Mathis 9 posts 29 karma points
    Aug 20, 2012 @ 17:03
    Stephane Mathis
    0

    Media sortOrder property returns 0

    Hi,

    I'm trying to sort a media folder programatically with the sortOrder property, the problem is that the property .sortOrder is always returning 0, even if on the backoffice I can see the real values.

    Is this a bug ? Did I misunderstood something ?
    I'm on Umbraco 4.7.2.

  • Nigel Wilson 945 posts 2077 karma points
    Aug 20, 2012 @ 22:35
    Nigel Wilson
    0

    Hi Stephane

    Can you provide your code so members are provide feedback ?

    Cheers

    Nigel

  • Stephane Mathis 9 posts 29 karma points
    Aug 21, 2012 @ 09:20
    Stephane Mathis
    0

    I have continued to search the problem and I get it.

    When I use a Media[] from a media.Children property, the sortOrder is always 0. But, if I re-create a media by using the id of my current media, I have the good value.

    Media[] medias = GetOrCreateMedia(currentNodeId, galeriesMediaId).Children;
    int i = medias[4].sortOrder;
    // i => 0

    Media m  = new Media(medias[4].Id);
    i = m.sortOrder;
    // i => 4

  • andrew 13 posts 36 karma points
    Apr 17, 2013 @ 20:56
    andrew
    0

    You're absolutely right -- I was iterating through an IEnumerable returned from GetDescendants() and adding them to a list if they met a certain criteria.  Instead of:

    foreach (mediaItem in mediaItems) {
    if (something) {
    listToReturn.Add(mediaItem);
    }

    I needed to use:

    foreach (mediaItem in mediaItems) {
    if (something) {
    listToReturn.Add(new Media(mediaItem.Id));
    }

    Thanks for pointing me in the right direction!  After that, returning a sorted list worked like a charm:

    return listToReturn.OrderBy(m => m.sortOrder).ToList();
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies