Copied to clipboard

Flag this post as spam?

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


  • alimac 177 posts 345 karma points
    Sep 25, 2012 @ 20:50
    alimac
    0

    Clearing out a media folder from Media.AfterSave event?

    Hi guys,

    I've written an event handler for the Media.AfterSave event that creates a group of folders within the added media item folder. It then creates some thumbnails based off this original media item and stores them in the newly created folders.

    So far I've managed to create the dynamic folders/images fine. The problem is when the user clicks 'remove file' in the media section and re-saves.

    This obviously clears the media file from the directory but I can't work out how to clear all the folders that were dynamically created within that same directory. How can I access the path of the file once it's been deleted? I figured I may have to do the cleanup in the BeforeSave event using:

    sender.getProperty("umbracoFile").Value.ToString()

    However this always returns "/" which means I can't find the directory that the image used to be in.

    Is there a recommended way of dealing with this situation? 

    Thanks

  • Ben McKean 260 posts 515 karma points
    Sep 27, 2012 @ 10:44
    Ben McKean
    1

    Do you mean the folder in the File System?

    If thats the case all the media items are stored in media\[Media ID]

    So you just need to get the Media ID and then pass that into a DeleteFile method.

     

     

  • Mads Krohn 211 posts 501 karma points c-trib
    Oct 22, 2012 @ 22:40
    Mads Krohn
    0

    Actually, that's not true I'm afraid. The id of the media item and the name of the media folder aren't always the same, you can't rely on them being the same. At least not in versions <= 4.9.0.

  • 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