Copied to clipboard

Flag this post as spam?

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


  • Dmitriy 168 posts 588 karma points
    Feb 07, 2020 @ 12:22
    Dmitriy
    0

    How to get a root media item?

    As I know, the root media ID is -1, anyway, next method works

    MediaService.CreateMedia("New media name", parentId: -1, "Folder");
    

    But the next one returns null:

    MediaService.GetById(-1); // null
    

    Why? How to get a root of media section?

  • Niels Henriksen 61 posts 264 karma points
    Feb 07, 2020 @ 13:40
    Niels Henriksen
    100

    The item with id -1 dont exists. Umbraco is using -1 in the parentid to see if the item is root.

    The item has a real id instead.

  • Dmitriy 168 posts 588 karma points
    Feb 07, 2020 @ 13:51
    Dmitriy
    0

    Hi, Niels

    Hmm, pretty ugly API unfortunatly :( Seems it is some kind of lagacy, magic numbers is antipattern :(

    By the way, I have found a litle better approach for it, it not the best, but better then nothing

    Constants.System.Root  // -1
    

    Thanks

Please Sign in or register to post replies

Write your reply to:

Draft