I've asked this one before but I've just been unable to find anything that works.
basically I have a page on which an integer is passed in on the query string, somewhere in the media content of my site I'm trying to find the media item based upon this name (ie 12341.png). Is it possible to search the media content knowing only a name of an item. Preferably I'd like to achieve this in a user control.
Do you have any code you're trying to get working that you can share with us?
I'm not that fluent in C# if that's what you're using but you should be able to use the umbraco.library:GetMedia() extension to fetch the media by the id from the querystring parameter.
Also what version of Umbraco are you using?
In the old API (In version before 4.10 I think) you should be able to do something like this
Media file =newMedia(mediaId); string url = file.getProperty("umbracoFile").Value.ToString();
In the above you then need to create a var mediaId with the value of the querystring.
Thanks for your help. What I've currently got (that doesn't work!) is the following. This is code that I've copied from another forum to try to get it to work. What this 'should' do (I think) is to loop the entire media directory and return a list of whats in there but like I say this doesn't return anything: The nodeName variable is passed in as string (myimage.doc for instance). To be honest I think that this is far more complex than I need it to be and I can't get it to work anyway!
Get media properties by its name
Hiya folks,
I've asked this one before but I've just been unable to find anything that works.
basically I have a page on which an integer is passed in on the query string, somewhere in the media content of my site I'm trying to find the media item based upon this name (ie 12341.png). Is it possible to search the media content knowing only a name of an item. Preferably I'd like to achieve this in a user control.
this is driving me mental!!!
Thanks,
craig
Hi Craig
Do you have any code you're trying to get working that you can share with us?
I'm not that fluent in C# if that's what you're using but you should be able to use the umbraco.library:GetMedia() extension to fetch the media by the id from the querystring parameter.
Also what version of Umbraco are you using?
In the old API (In version before 4.10 I think) you should be able to do something like this
In the above you then need to create a var mediaId with the value of the querystring.
Looking forward to hearing from you.
/Jan
Hi Jan,
Thanks for your help. What I've currently got (that doesn't work!) is the following. This is code that I've copied from another forum to try to get it to work. What this 'should' do (I think) is to loop the entire media directory and return a list of whats in there but like I say this doesn't return anything: The nodeName variable is passed in as string (myimage.doc for instance). To be honest I think that this is far more complex than I need it to be and I can't get it to work anyway!
string zMedia = "";
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);
zMedia = zMedia + (mediaItem);
}
}
return zMedia;
Do you have a solution yet?
Hiya Mate,
Yes I sorted it in the end. If you want the code I'll post it up for you early next week (I'm at work at the min)
Craig
As an update to Jan Skovaards answer...
In later versions of Umbraco you can use 'getPropertyValue' to get media properties.
is working on a reply...