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)
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.
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();
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.
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:
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
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
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
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
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
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
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
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
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
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
is working on a reply...