I'm fresh off the boat on the Umbracian shore, so foregive me if this is a stupid question... :)
I'm working on my first Umbraco-tuned .NET User Control, and want to get the URL specified by picking a media-picture in Umbraco.
Here´s my boiled down code:
Property pic = page.GetProperty("Picture"); // This property is the mediaPicker property if (pic != null && !String.IsNullOrEmpty( pic.Value ) ) { Image picture = new Image(); picture.ImageUrl = umbraco.library.NiceUrl(Convert.ToInt32(pic.Value)); // <-- This is the culprit! container.Controls.Add(picture); }
The problem is that umbraco.library.NiceUrl returns an empty string! :( Is this function only for XSLT use?
I have checked that page.GetProperty("Picture").Value returns an integer value, which tells me that there actually is a picture set. Or what?
I noticed the function umbraco.library.GetMedia, but this doesn't seem fit for my purpose either... ?
Getting mediaPicker URL from User Control!?
Hi,
I'm fresh off the boat on the Umbracian shore, so foregive me if this is a stupid question... :)
I'm working on my first Umbraco-tuned .NET User Control, and want to get the URL specified by picking a media-picture in Umbraco.
Here´s my boiled down code:
Property pic = page.GetProperty("Picture"); // This property is the mediaPicker property
if (pic != null && !String.IsNullOrEmpty( pic.Value ) )
{
Image picture = new Image();
picture.ImageUrl = umbraco.library.NiceUrl(Convert.ToInt32(pic.Value)); // <-- This is the culprit!
container.Controls.Add(picture);
}
The problem is that umbraco.library.NiceUrl returns an empty string! :( Is this function only for XSLT use?
I have checked that page.GetProperty("Picture").Value returns an integer value, which tells me that there actually is a picture set. Or what?
I noticed the function umbraco.library.GetMedia, but this doesn't seem fit for my purpose either... ?
Any help would be appreciated, thanks!
Regards
Alex
Alex,
Replace:
with:
Hope this helps.
Regards,
/Dirk
Oops, have forgotten to declare the mediaItem variable:
Cheers,
/Dirk
Thanks Dirk! That did the trick.
Just needed to add ".Value" on the property, which resulted in the final code:
I also needed references to the businesslogic.dll and cms.dll assemblies to get access to the Media class.
Thanks again. I'm off to my next challenge: UpdatePanels in my Umbraco User Control.... ;)
/Alex
is working on a reply...