Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
How can I get media(folder) by name.
Thanks
Hi Kukuwka,
There isn't really possible out of the box, but you could write a helper method to do it.
Take a look at Hendys helper methods for umbraco
http://blog.hendyracher.co.uk/umbraco-helper-class/
He has one for GetNodesByName which you could modify to work with media items.
Many thanks
Matt
I want get media name from Section Media ,but not from umbraco.config.
Something like: Instead function "GetMedia(int itemid)" to use "GetMedia(string name)" .
Is there such a possibility?
Don't know if you figured this out, but I modified some of the code in the uComponents library to do this.
public static List<Media> GetMediaByName(string nodeName) { List<Media> media = new List<Media>(); XmlDocument xmlDocument = uQuery.GetPublishedXml(uQuery.UmbracoObjectType.Media); XPathNavigator xPathNavigator = xmlDocument.CreateNavigator(); XPathNodeIterator xPathNodeIterator = xPathNavigator.Select("descendant::*[@nodeName='" + nodeName + "']"); Media mediaItem; while (xPathNodeIterator.MoveNext()) { mediaItem = uQuery.GetMedia(xPathNodeIterator.Current.Evaluate("string(@id)").ToString()); if (mediaItem != null) { media.Add(mediaItem); } } return media; }
Hope this helps. Better late than never.
-C
Hi Chad,
Yeah, that method should be in the API :) have just added:
public static List<Media> GetMediaByName(string name){ return uQuery.GetMediaByXPath("descendant::*[@nodeName='" + name + "']");}
Cheers,
Hendy
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Get media by name
Hi,
How can I get media(folder) by name.
Thanks
Hi Kukuwka,
There isn't really possible out of the box, but you could write a helper method to do it.
Take a look at Hendys helper methods for umbraco
http://blog.hendyracher.co.uk/umbraco-helper-class/
He has one for GetNodesByName which you could modify to work with media items.
Many thanks
Matt
I want get media name from Section Media ,but not from umbraco.config.
Something like: Instead function "GetMedia(int itemid)" to use "GetMedia(string name)" .
Is there such a possibility?
Thanks
Don't know if you figured this out, but I modified some of the code in the uComponents library to do this.
Hope this helps. Better late than never.
-C
Hi Chad,
Yeah, that method should be in the API :) have just added:
Cheers,
Hendy
is working on a reply...