Copied to clipboard

Flag this post as spam?

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


  • Dante 7 posts 78 karma points
    May 09, 2017 @ 14:22
    Dante
    0

    Get parent node name into IApplicationEventHandler

    Hi guys, I built a class that inherit from IApplicationEventHandler to intercept the media Item save.

    public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            /* La chiamata si verifica dopo il salvataggio. */
            MediaService.Saved += MediaServiceSaved;
    
        }
    
    void MediaServiceSaved(IMediaService sender, SaveEventArgs<IMedia> e)
            {
            ..........
                foreach (IMedia mediaItem in e.SavedEntities)
                {
                    int parentId = mediaItem.ParentId;
                    string path = mediaItem.Path;
    
                Node parentNode = new Node(parentId);
        ......
        }
    

    Now I need to take the parentNode.Name but parentNode is always null. My question is: How can I get the parentNode usgin parentId, I need to take the folder name where I'm uploading the image.

    Thanks in advance. Dante.

  • Stefan Verleger 2 posts 72 karma points
    May 10, 2017 @ 11:05
    Stefan Verleger
    0

    Hi Dante,

    you are in the Media section. So the parent node is also an media item.

    Take the MediaService to get the parent node

    var mediaService = ApplicationContext.Current.Services.MediaService;
    var parentNode = mediaService.GetById(parentId);
    

    Stefan

  • Dante 7 posts 78 karma points
    May 10, 2017 @ 13:53
    Dante
    0

    Hi Stefan, thank you very much for your support.

    Regards. Dante

  • 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