Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Jan 12, 2011 @ 10:56
    Anthony Candaele
    0

    list of documents

    Hi,

    I need to implement a page that reads out all documents from the media library.

    I wonder if someone knows where I can find an xslt-example for this or a package or extension?

    Thanks for your advice,

    Anthony Candaele
    Belgium

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 12, 2011 @ 11:07
    Dirk De Grave
    2

    Anthony,

    Can use the umbraco library function GetMedia(nodeId, deep) for that, although not recommended as it may be resource intensive in terms of sql statements (especially if you're on a pre 4.5 version). Be warned!

    nodeId  is the starting node from which to get a list of docs from

    deep is a boolean indicating whether to get a single media item or returning all items underneath the starting node

    If you're familiar with the db structure, it might be a good idea to get all media using some sql queries as well (and build an xslt extension method to return results for your xslt)

     

    Cheers,

    /Dirk

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

    Hi Anthony

    I'lll just supply the Dikr's great answer with the description of GetMedia in the wiki, which contains some usefull examples: http://our.umbraco.org/wiki/reference/umbracolibrary/getmedia

    /Jan

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 12, 2011 @ 12:08
    Anthony Candaele
    0

    Hi Dirk and Jan,

    Thanks for your assistance. I'll try out the GetMedia method to produce a list of documents from the Media library. I'll keep you informed on my progress.

    Anthony

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jan 12, 2011 @ 12:19
    Hendy Racher
    2

    Hi Anthony,

    If you want to retrieve all Media items of a particular mediaType there's a helper library called uQuery in the uComponents package that has a method GetMediaByType() that will return a List<Member> collection (internally this uses GetMediaByXPath which returns the result set from a single DB hit).

    If you want to return the whole media tree, the GetMediaByXPath("descendant::*"); could be useful, or looping though Media.GetDescendants();

    HTH,

    Hendy

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 12, 2011 @ 16:17
    Anthony Candaele
    0

    Hi Hendy,

    I download the uComponents package, but I cannot find the uQuery helper library.

    I just wonder if there is no way to loop trough a folder in the Media library without this uComponents helper method?

    thanks for your advice,

    Anthony

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Jan 12, 2011 @ 16:56
    Hendy Racher
    0

    Hi Anthony,

    As Dirk suggests you can use the umbraco.library.GetMedia(mediaFolderId, true) method to return an XPathNodeIterator, from which you can loop though all items beneath a the supplied mediaFolderId - I believe the deep parameter will toggle whether you want just the specified node (false) or itself and all descendants (true).

    Alternativily you can use Children property of the umbraco.cms.businesslogic.media.Media object to return an array of Media objects.

    BTW, the uQuery static class is in the uComponents.Core namespace, and the extenion methods in the uComponents.Core.uQueryExtensions namespace.

    HTH,

    Hendy

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 13, 2011 @ 10:31
    Anthony Candaele
    0

    Hi,

    I'm a bit further now, I managed to list all my documents in the 'Documents' folder (id 1088) in the Media Library. I uploaded two files, a .pdf and a .docx document but my unordered list shows only the .pdf document ... twice! This is my code:

    <xsl:variable name="documents" select="umbraco.library:GetMedia('1088', 'false')"/>

        <xsl:template match="/">
            <xsl:if test="$documents">
              <ul>
                <xsl:for-each select="$documents/File">
                  <li><a href="{$documents/File/umbracoFile}" target="_blank"><xsl:value-of select="$documents/File/@nodeName" /></a></li>
                </xsl:for-each>
              </ul>
            </xsl:if>
        </xsl:template>

    What am I doing wrong here?

    Thanks for your assistance

    Anthony Candaele

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 13, 2011 @ 11:05
    Anthony Candaele
    0

    After browsing the forum a bit, I was able to get it to work, this is my code:

    <xsl:param name="currentPage"/>
    <xsl:variable name="documents" select="umbraco.library:GetMedia(1088, 1)"/>

        <xsl:template match="/">
            <xsl:if test="count($documents) > 0">
              <ul>
                <xsl:for-each select="$documents/*">
                  <xsl:if test="./umbracoFile != ''">
                  <li><a href="{./umbracoFile}" target="_blank"><xsl:value-of select="./@nodeName" /></a></li>
                  </xsl:if>
                  </xsl:for-each>
              </ul>
            </xsl:if>
        </xsl:template>

    Anthony Candaele

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 13, 2011 @ 11:10
    Anthony Candaele
    0

    Now I get my list of documents to work, I would also like to show other information about the uploaded document like (modified date etc ...)

    Is there a place where I can check the xml node properties of a File in the media library?

    Thanks for your advice,

    Anthony Candaele

Please Sign in or register to post replies

Write your reply to:

Draft