Copied to clipboard

Flag this post as spam?

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


  • wilenx 16 posts 66 karma points
    Oct 29, 2013 @ 14:47
    wilenx
    0

    How to create Media object at the root of the Media section ?

    I'm using Umbraco v6.1.6 and can't seem to figure out how to create a Media object at level 1, where its parent is the root.

    This code returns a new node with Id=0, and I don't know what I'm doing wrong:

    IMedia newNode = new Media("name", -1, contentType);
    
  • wilenx 16 posts 66 karma points
    Oct 30, 2013 @ 11:20
    wilenx
    100

    For those who may also struggle with this in the future, use the following:

    IMediaService _mediaService = ApplicationContext.Current.Services.MediaService;
    IMedia newNode = _mediaService.CreateMedia(name, parentId, mediaTypeAlias);
    ApplicationContext.Current.Services.MediaService.Save(newNode);
    

    The Save() method will do the trick.

  • Murray Roke 503 posts 967 karma points c-trib
    Sep 07, 2017 @ 04:07
    Murray Roke
    1

    but at the root what is the parentId?

  • 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