Here is what I am using to retrieve image URL from media id
public string GetImageUrlFromNodeId(int mediaId)
{
Media mediaFile = new Media(mediaId);
return mediaFile.getProperty("umbracoFile").Value.ToString();
}
As I said before you shouldn't use the Document API in a usercontrol which is used in your website. If your usercontrol is used as a datatype you can use the Document API, but otherwise you need to use the Node API which is 10x faster.
Node.GetProperty Returning a number I want the image URL form Media picker
Hello guys I have an umbraco document type and one of the properties is a Media Picker
I have a usercontrol and I am trying to get the URL of the image that was selected for that property.
var x = imageNode.GetProperty("image").Value;
This is returning a number, which I think is an Id of some kind, but I want the URL of the image.
Any ideas...please?
If you are using razor you can do something like this;
Cheers
Evan
Here is what I am using to retrieve image URL from media id
Hi SideSam,
You shouldn't use that code. It uses the Media API which is very slow and should only be used to modify media. Evan his example is good.
This wiki is about the Document API, but it's the same for Media: http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-a-node-and-a-document.
Jeroen
I am not using razor its in a user control, Jeroen good you past a code snippit please?
In a usercontrol you need to look at the Document API.
http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties
Hi Evan,
As I said before you shouldn't use the Document API in a usercontrol which is used in your website. If your usercontrol is used as a datatype you can use the Document API, but otherwise you need to use the Node API which is 10x faster.
Again read this wiki: http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-node-and-document and also this blog with more info: http://www.netaddicts.be/articles/document-api-vs-nodefactory.aspx.
In a usercontrol you can also use Razor code. Something like this should work:
I didn't test that code, but something like that should work.
Jeroen
is working on a reply...