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.
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.
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:
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
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:
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
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
Something like that would match (didn't test it yet)
hth, Thomas
Vote for it: http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=23580
Thomas
@Thomas - Thanks, I voted :-)
is working on a reply...