Copied to clipboard

Flag this post as spam?

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


  • Gordon Saxby 1461 posts 1883 karma points
    Mar 29, 2011 @ 16:41
    Gordon Saxby
    0

    Get Media node from physical path

    I have website search results that return the path to documents in the Media Library - how do I select the Media Library node for file?

    /media/12345/file.pdf - how do I get the node in Umbraco?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 29, 2011 @ 22:12
    Jan Skovgaard
    0

    Hi Gordon

    Do you want the full path for the media nodes to be displayed on the search result? Or is it in Umbraco you're in doubt about how you select the media node? Or do you just need to know how to write out the path for the file with XSLT?

    I'm not quite sure what it is that you need :-)

    /Jan

  • Gordon Saxby 1461 posts 1883 karma points
    Mar 30, 2011 @ 00:25
    Gordon Saxby
    0

    As per the example I put in my post, the search result (from a Google Search Appliance as XML) is returning the physical path to the PDF. I want to find that PDF in the media library so that I can get the name given to it in the media library - rather than the physical file name.

    Unfortunately, the number in the path which relates to the folder that contains the PDF is not the ID of the Media Library node. I cannot see any builtin Umbraco functions that will allow me to get the Media Library node and hence name.

    I have investigated the database and found a way of locating the node ID, but it is not a solution I like.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 30, 2011 @ 18:21
    Sebastiaan Janssen
    1

    Here's a topic that deals with this same issue.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 30, 2011 @ 21:48
    Chriztian Steinmeier
    1

    Hi Gordon,

    This is a crude way to do it, mainly because it forces you to collect all the Media items' XML into a variable, but once you've got that it's really a walk in the park (or on the 'X Path' so to speak :-)

    If you've got all the PDFs in a single folder, for God's sake use that folder's ID as the MEDIA_NODE_ID.

    <!-- Fetch ALL media items below MEDIA_NODE_ID: -->
    <xsl:variable name="media" select="umbraco.library:GetMedia(MEDIA_NODE_ID, true())" />
    
    <!-- Sample result -->
    <xsl:variable name="pdfFileName" select="'/media/1057/Season-4_Episode-5_The-Constant.pdf'" />
    
    <!-- Find the File... -->
    <xsl:apply-templates select="$media//File[substring-after(umbracoFile, '/media/') = substring-after($pdfFileName, '/media/')]" />
    
    <!-- Reusable template for File elements -->
    <xsl:template match="File">
        <p class="result">
            <a href="{umbracoFile}" type="application/pdf"><xsl:value-of select="@nodeName" /></a>
        </p>
    </xsl:template>

    Chriztian 

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 30, 2011 @ 22:27
    Lee Kelleher
    0

    I'm feeling a uComponents uQuery/XsltExtension coming on here! :-D

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 30, 2011 @ 22:43
    Lee Kelleher
    2

    Man... I'm so crazy, we can already do this in uComponents! :-D

    OK, so we've got these new Search methods, right? Try this...

    <xsl:variable name="filename" select="string('/media/1234/filename.pdf')" />
    <xsl:variable name="mediaNodes" select="ucomponents.search:AdvancedSearch(concat('umbracoFile=', $filename), false(), 'InternalSearcher', 'media')" />
    <xsl:if test="$mediaNodes">
        <xsl:value-of select="$mediaNodes/*[@isDoc]/@id" />
    </xsl:if>

    This is all based on the assumption that you have uComponents AND a valid/stable/up-to-date Examine/Lucene index!

    Cheers, Lee.

  • Gordon Saxby 1461 posts 1883 karma points
    Mar 31, 2011 @ 10:36
    Gordon Saxby
    0

    Have uComponents ... Examine/Lucene ... not sure!? If it's not there by default then no.

    I tried the code anyway and it doesn't work :-(

  • Fergus Davidson 309 posts 588 karma points
    Mar 31, 2011 @ 11:23
    Fergus Davidson
    0

    Hi, forgive me if this is a silly question, but do you have the latest version of uComponents? - [2.1, i think]

    the search extensions do not appear in earlier versions

  • Gordon Saxby 1461 posts 1883 karma points
    Mar 31, 2011 @ 11:58
    Gordon Saxby
    0

    Yes, I have the latest version but I just get "no results" back.

     

Please Sign in or register to post replies

Write your reply to:

Draft