Copied to clipboard

Flag this post as spam?

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


  • How Do I Delete My Account? 68 posts 433 karma points
    Jan 18, 2016 @ 13:55
    How Do I Delete My Account?
    1

    Get media file by filename

    Hi!

    Is it possible to get a media-content by filename? If so, how?

  • Søren Kottal 587 posts 3769 karma points MVP 3x c-trib
    Jan 18, 2016 @ 19:25
    Søren Kottal
    2

    I'm pretty sure, that media is indexed in the Internal index, so maybe you can reverse engineer through an Examine search.

            var internalSearcher = ExamineManager.Instance.SearchProviderCollection["InternalSearcher"];
            var query = internalSearcher.CreateSearchCriteria().Field("umbracoFile", "my-image.jpg").Compile();
            var media = Umbraco.TypedSearch(query);
    

    That would give en IEnumerable of IPublishedContents, where umbracoFile (the upload property) is equal to my-image.jpg.

  • How Do I Delete My Account? 68 posts 433 karma points
    Feb 05, 2016 @ 12:54
    How Do I Delete My Account?
    101

    Solid idea, I was thinking about something similar. However. I solved it with creating a folder in the project outside of umbraco, put the images there instead and mapped the folder and then just used

    File.exists(mappedPath + filename + ".jpg")
    

    If it existed I could just put a relative link in there (because I know the name of the folder), for example:

    imgUrl = "/imgFolder/" + filename + ".jpg";
    

    Hope it helped anyone else.

Please Sign in or register to post replies

Write your reply to:

Draft