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.
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
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:
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.
Hi Stephane
Can you provide your code so members are provide feedback ?
Cheers
Nigel
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
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:
I needed to use:
Thanks for pointing me in the right direction! After that, returning a sorted list worked like a charm:
is working on a reply...