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.
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.
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.
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..?
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
Hi Froad,
If you have uComponents installed, how about getting the media based on an XPath query ? (I've not tested the query)
This methods hits the DB once, so should also be fast.
HTH,
Hendy
But can I use the uComponents datatypes in my usercontrol?
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
Sweet! Thanks! Gonna look in to it :)
Hi Froad,
Having just looked at how the tags datatype stores it's data (which I'm assuming you're using)
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
is working on a reply...