Copied to clipboard

Flag this post as spam?

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


  • Jan Molbech 40 posts 126 karma points
    Dec 12, 2014 @ 10:36
    Jan Molbech
    0

    Getting a mediafile by its name

    How do i find a media image by it's name from code?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 12, 2014 @ 10:39
    Dave Woestenborghs
    0

    Can I ask why you want to get it by name ? Names can be changed by editors and that way your code breaks.

    Also maybe you can explain what your are trying to achieve. Maybe there is another solution to your requirement.

  • Jan Molbech 40 posts 126 karma points
    Dec 12, 2014 @ 10:44
    Jan Molbech
    0

    I have to display a image with a certain name. The editor knows that the image won't be displayed unless it's named correctly

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 12, 2014 @ 10:49
    Dave Woestenborghs
    0

    Why don't you add a media picker to your doctype. That way the editor can change the image and you can get it by Id ?

    Dave

  • Jan Molbech 40 posts 126 karma points
    Dec 12, 2014 @ 10:54
    Jan Molbech
    0

    So it's not possible to get a media file by its name i guess.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 12, 2014 @ 10:56
    Dave Woestenborghs
    100

    It is possible. I just won't recommend it. One editor may now that he can not change the name, but another one can forget and change it and break the site

    In uQuery there is a method to get media by name.

    See documentation : http://our.umbraco.org/documentation/Reference/Querying/uQuery/Media

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft