Copied to clipboard

Flag this post as spam?

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


  • Kieron McIntyre 108 posts 326 karma points
    Oct 08, 2013 @ 19:43
    Kieron McIntyre
    0

    Saving the SortOrder using MediaService.Creating

    I have the following code which I hoped would force all Folder media items to appear first in their list.

    public class CreateEvent : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase a, ApplicationContext c)
        {
            MediaService.Creating += MediaService_Creating;
        }
    
        void MediaService_Creating(IMediaService sender, NewEventArgs<IMedia> e)
        {
            if (e.Entity.ContentType.Alias.EndsWith("Folder"))
            {
                e.Entity.SortOrder = 0;
            }
        }
    }
    

    Unfortunately, Umbraco seems to ignore the value I am setting. Presumably because it is working out the SortOrder after this event is fired.

    Any ideas how I can overcome this? Ideally, I would like to be able to set the SortOrder and not then have to reload the content tree :)

  • Tim 1193 posts 2655 karma points c-trib
    Oct 10, 2013 @ 15:21
    Tim
    0

    You could try one of the events that fires after the creation is complete maybe? Try MediaService.Created instead and see if that works.

  • Kieron McIntyre 108 posts 326 karma points
    Oct 10, 2013 @ 15:27
    Kieron McIntyre
    0

    Yeah I've tried that too. I'm surprised there isn't an obvious means to do this. Time to go to the source ...

  • Søren Kottal 530 posts 3521 karma points MVP 2x c-trib
    Aug 25, 2015 @ 13:33
    Søren Kottal
    0

    Did you find a solution?

    I'm having the same problem with the contentservice.

  • 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