Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 594 posts 830 karma points
    Dec 22, 2010 @ 09:30
    Fredrik Esseen
    0

    Gett all media from the media section in codebehind

    Hi!

    I want to add possibility to search the whole media section in the frontend and display images depending on the tags that is connected to the image.

    Ive created a property to the media type called tags.

    Im thinking of doing this in a usecontrol and need some example code for iterating all nodes in the media section.

    Does anyone have a snippet..?

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Dec 22, 2010 @ 10:02
    Jeroen Breuer
    1

    Using the Media object can be very slow because each time you use getProperty you make a call to the db. The best solution I think is to get all the media items using library.GetMedia(id, true). This will return all the media items under a certain folder (parent) as a XPathNodeIterator object. I always convert this to an XDocument and use Linq to Xml to get the required data. I thinks that's the fastest solution.

    Jeroen

  • Hendy Racher 861 posts 3844 karma points MVP 2x admin c-trib
    Dec 22, 2010 @ 10:15
    Hendy Racher
    0

    Hi Froad,

    If you have uComponents installed, how about getting the media based on an XPath query ? (I've not tested the query)

    List<Media> media = uQuery.GetMediaByXPath("descendant::*[tags='value']");

    This methods hits the DB once, so should also be fast.

    HTH,

    Hendy

  • Fredrik Esseen 594 posts 830 karma points
    Dec 22, 2010 @ 10:19
    Fredrik Esseen
    0

    But can I use the uComponents datatypes in my usercontrol?

  • Hendy Racher 861 posts 3844 karma points MVP 2x admin c-trib
    Dec 22, 2010 @ 10:31
    Hendy Racher
    1

    Hi Froad,

    It's just a static helper library that's a part of the uComponents package, all you need to do is add a reference to the uComponents.Core.dll in your solution, and then the uComponents.Core.uQuery class will be available.

    HTH,

    Hendy

  • Fredrik Esseen 594 posts 830 karma points
    Dec 22, 2010 @ 10:47
    Fredrik Esseen
    0

    Sweet! Thanks! Gonna look in to it :)

  • Hendy Racher 861 posts 3844 karma points MVP 2x admin c-trib
    Dec 22, 2010 @ 11:03
    Hendy Racher
    0

    Hi Froad,

    Having just looked at how the tags datatype stores it's data (which I'm assuming you're using)

    <mediaItem.... ><tags><![CDATA[tag1,tag2]]></tags></mediaItem>

    Jeroens suggestiong of Linq to Xml looks like the best approach (as you'll need to parse the CSV of tags, which would be safer than an XPath expression looking for a string match in the CSV)

    Alternatively a collection of potential media items could be retrieved and then Linq to Objects used - but I would expect Linq to Xml to be faster in this instance.

    Cheers,

    Hendy

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies