Copied to clipboard

Flag this post as spam?

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


  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 15, 2010 @ 10:00
    Ferdy Hoefakker
    0

    Getting ALL files from media section

    Hi everyone,

    I need an XSLT that can fetch ALL items under the media section. I have managed to get this, but ONLY if they are under a folder. My XSLT:

    <xsl:for-each select="umbraco.library:GetMedia("1061", 'false')/../descendant::node">

    Like I said, this works. But I only files placed under the folder with id 1061 (oh and it's recursive so it also loops through the subfolders (which I want)). This is all nice, but I want it to loop through ALL my files.

    As can been seen in the code, I tried "/.." to go to the parent container (in this case that would be the root of the media section). This worked for my pages, but for the files it just doesn't seem to be working. If anyone could shed some light on this, I would really appreciate it.

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 10:06
    Thomas Höhler
    0

    You can implement your own xslt extension. Take a look into this thread: http://our.umbraco.org/forum/developers/xslt/3099-GetXmlAll%28%29-Equivalent-for-Media

    hth, Thomas

  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 15, 2010 @ 10:08
    Ferdy Hoefakker
    0

    Thanks for the reply Thomas. I take it this means it is impossible to do it in any other way?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 10:14
    Thomas Höhler
    0

    Jup, there is no build in way to fetch the root media items via xslt. So you have to implement it by yourself. But the code in the other thread should do it.

    Thomas

  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 15, 2010 @ 10:17
    Ferdy Hoefakker
    0

    Allright, thanks a lot Thomas. I'll go do that then.

  • Sajid Riaz 142 posts 165 karma points
    Jul 15, 2010 @ 10:20
    Sajid Riaz
    0

    Hi, you could create a mediapicker property in yr doc type, and then in yr content page set the media folder as the source for that property.  You can then use xslt to get all the items using that property.

    >sajid

  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 15, 2010 @ 10:22
    Ferdy Hoefakker
    0

    Hi Sajid,

    Unless I misunderstand you, this will not work because I can not select the root of the media section with the mediapicker. It returns -1, which is an invalid node id.

  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 15, 2010 @ 10:51
    Ferdy Hoefakker
    0

    Thomas,

    I am currently trying to implement the XSLT extension, but I seem to be missing a "using directive" or an "assembly reference". Is there an Umbraco dll I should be referencing?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 15, 2010 @ 12:23
    Thomas Höhler
    0

    yep, it's a reference to cms.dll from umbraco where you use the namespace umbraco.cms.businesslogic.media

    Thomas

  • Ferdy Hoefakker 214 posts 248 karma points
    Jul 15, 2010 @ 15:35
    Ferdy Hoefakker
    0

    Thank you Thomas, I got that part fixed. It seems however, that the code is not correct as it gives me a "System.InvalidOperationException: This document has a Document Element node" whenever I try to save the XSLT.

    Edit:

    Thomas, after playing around a bit with your code (and some googling) I made some minor changes to it.

    try
    {
    XmlDocument xml = new XmlDocument();
    xml.AppendChild(xml.CreateElement("mediaRoot"));
    foreach (Media item in Media.GetRootMedias())
    {
    if (item.nodeObjectType == Media._objectType)
    {
    xml.DocumentElement.AppendChild(item.ToXml(xml,true));
    }
    }
    XPathNavigator xp = xml.CreateNavigator();
    return xml.CreateNavigator().Select("/");
    }
    catch
    {
    XmlDocument xd = new XmlDocument();
    xd.LoadXml("<error>Error at getting the root medias</error>");
    return xd.CreateNavigator().Select("/");
    }

    This is tested and works for me.

    <xsl:for-each select="bmExt:GetRootMedias('true')/descendant::node [@nodeTypeAlias!='Folder']">

    Is what I can now use to loop through each and everyone of my media items. Thank you very much for the help :)

  • Jeroen Ribbink 21 posts 50 karma points
    Mar 02, 2011 @ 09:07
    Jeroen Ribbink
    0
Please Sign in or register to post replies

Write your reply to:

Draft