Umbraco.TypedContentAtXPath to find specific file in Media
Hello !
I am trying to use TypedContentAtXPath() to find a specific file in a specific subfolder in my Media library. The reason for this is that instead of using
var mediaFolder = Umbraco.Media(folderId)
var desiredfile = mediafolder.Children.Where(x => x.name == nameoffile)
I would like to not create an IPublishedContent object for each item in the folder when I would use a linq query through it to find my file.
I have been trying to do, for example:
var folder = Umbraco.TypedContentAtXPath("//Folder");
var folder = Umbraco.TypedContentAtXPath("//Folder[@name='pdf']");
var folder = Umbraco.TypedContentAtXPath("//folder[@id='folderId']")
//folderId comes from dictionary.
And yet I can't seem to get any results. Or even reach the media folder at all.
I haven't worked a lot with Xpath's or Xml's in the past, but I can't seem too find much documentation on this function and all the forum posts just end up going the default way, which I pointed in the beginning. Am I missing something like a decleration? Or even misunderstanding the ability of this function?
To clarify, I need to find a specific media file, in a specific folder, that contains a specific string in its name, and is the newest one of the ones found in that folder. Using TypedContentAtXPath.
The TypedContentAtXPath method will query the XML for the content tree, rather than the media tree, however there is a legacy API that where you can make an XPath query against the media data: umbraco.uQuery.GetMediaByXPath(), but it might be better to make a Lucene query instead.
Umbraco.TypedContentAtXPath to find specific file in Media
Hello !
I am trying to use TypedContentAtXPath() to find a specific file in a specific subfolder in my Media library. The reason for this is that instead of using
I would like to not create an IPublishedContent object for each item in the folder when I would use a linq query through it to find my file.
I have been trying to do, for example:
And yet I can't seem to get any results. Or even reach the media folder at all.
I haven't worked a lot with Xpath's or Xml's in the past, but I can't seem too find much documentation on this function and all the forum posts just end up going the default way, which I pointed in the beginning. Am I missing something like a decleration? Or even misunderstanding the ability of this function?
To clarify, I need to find a specific media file, in a specific folder, that contains a specific string in its name, and is the newest one of the ones found in that folder. Using TypedContentAtXPath.
Hi Kristján,
The TypedContentAtXPath method will query the XML for the content tree, rather than the media tree, however there is a legacy API that where you can make an XPath query against the media data: umbraco.uQuery.GetMediaByXPath(), but it might be better to make a Lucene query instead.
Thank you, GetMediaByXpath() is exactly what I needed :)
is working on a reply...