Copied to clipboard

Flag this post as spam?

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


  • anthony hall 222 posts 536 karma points
    Jul 11, 2011 @ 18:35
    anthony hall
    0

    How can i get the file type of a media items

    How can i get the file type of a media items. ie jpg , pdf etc. 

     

        <xsl:variable name="file1" select="number($currentPage/file1)" />
      <xsl:value-of select="$file1"/>
      <xsl:if test="$file1 &gt; 0">
        
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($file1 , 0)" />
       
          <xsl:if test="string($mediaNode/umbracoFile) != ''">
            <href="{$mediaNode/umbracoFile}" alt="[image]">
            <xsl:value-of select="$mediaNode/@nodeName" /> 
            </a>
          
        </xsl:if>
      </xsl:if>
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 11, 2011 @ 19:00
    Tom Fulton
    1

    Hi Anthony,

    You can access the umbracoExtension property of a Media Item, eg:

    <xsl:choose>
     <xsl:when test="Exslt.ExsltStrings:uppercase($mediaNode/umbracoExtension) = 'JPG'">
      this is a .jpg file
     </xsl:when>
    </xsl:choose>

    I threw an uppercase in there as I'm not sure if Umbraco changes the case of the extension or uses the exact one on the file, so this will handle either case.

    -Tom

Please Sign in or register to post replies

Write your reply to:

Draft