Copied to clipboard

Flag this post as spam?

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


  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Jul 22, 2009 @ 01:26
    Heather Floyd
    0

    GetXmlAll() Equivalent for Media?

    Hi, I was just wondering if there is any way to get ALL the Media nodes, similar to umbraco.library:GetXmlAll()? I tried this:

    <xsl:variable name="AllMediaNodes" select="umbraco.library:GetMedia(-1, 1)"/>

    Since "-1" is listed as the root in all media Paths, but that didn't work (It returns "No media is maching '-1'")

    Thanks!

    ~Heather

  • Chris Houston 535 posts 980 karma points MVP admin c-trib
    Jul 22, 2009 @ 02:56
    Chris Houston
    0

    Hi Heather,

    I have just had a look at the Umbraco source for GetMedia, from what I can see it won't work with -1 as this is not a node and hence the statement checking if the node is a media type will fail as you can see below:

            public static XPathNodeIterator GetMedia(int MediaId, bool Deep)
    {
    try
    {
    Media m = new Media(MediaId);
    if (m.nodeObjectType == Media._objectType)
    {
    XmlDocument mXml = new XmlDocument();
    mXml.LoadXml(m.ToXml(mXml, Deep).OuterXml);
    XPathNavigator xp = mXml.CreateNavigator();
    return xp.Select("/node");
    }
    }
    catch
    {
    }

    XmlDocument xd = new XmlDocument();
    xd.LoadXml(string.Format("<error>No media is maching '{0}'</error>", MediaId));
    return xd.CreateNavigator().Select("/");
    }

    I have just tried all sorts of other options but none seem to work.

    I think the easiest solution would be to ensure all your content is stored within one root folder, but assuming that you already have a media folder full of media and this is not possible, then you could write your own GetAllMedia function that returned all media nodes based on the GetMedia function above.

    Best regards,

    Chris

  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Jul 22, 2009 @ 04:30
    Heather Floyd
    0

    Thanks, Chris,

    That's what I feared :-)

    Maybe when I have some time I will look at creating the function... In the meantime, I think I will be able to do what you suggest, at least for this project.

    Have a great day!

    Heather

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 22, 2009 @ 10:35
    Thomas Höhler
    1

    Something like that would match (didn't test it yet)

    public static XPathNodeIterator GetRootMedias(bool Deep)
    {
    try
    {
    XmlDocument xml = new XmlDocument();
    xml.AppendChild(xml.CreateElement("mediaRoot"));

    foreach (Media item in Media.GetRootMedias())
    if (item.nodeObjectType == Media._objectType)
    xml.AppendChild(item.ToXml(xml, Deep));

    XPathNavigator xp = xml.CreateNavigator();
    return xp.Select("/mediaRoot");
    }
    catch
    {
    }

    XmlDocument xd = new XmlDocument();
    xd.LoadXml("<error>Error at getting the root medias</error>");
    return xd.CreateNavigator().Select("/");
    }

    hth, Thomas

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Jul 22, 2009 @ 10:39
  • Heather Floyd 610 posts 1032 karma points MVP 6x c-trib
    Jul 24, 2009 @ 20:17
    Heather Floyd
    0

    @Thomas - Thanks, I voted :-)

Please Sign in or register to post replies

Write your reply to:

Draft