Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex Kørup 17 posts 39 karma points
    Jul 08, 2009 @ 14:58
    Alex Kørup
    0

    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

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 08, 2009 @ 15:47
    Dirk De Grave
    1

    Alex,

     

    Replace:

    picture.ImageUrl = umbraco.library.NiceUrl(Convert.ToInt32(pic.Value));

    with:

     

    Hope this helps.

     

    Regards,

    /Dirk

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 08, 2009 @ 15:48
    Dirk De Grave
    2

    Oops, have forgotten to declare the mediaItem variable:

     

    var mediaItem = new Media(Convert.ToInt32(pic.Value));

     

    Cheers,

    /Dirk

  • Alex Kørup 17 posts 39 karma points
    Jul 08, 2009 @ 16:41
    Alex Kørup
    1

    Thanks Dirk! That did the trick.

    Just needed to add ".Value" on the property, which resulted in the final code:

    Image picture = new Image();
    Media picMedia = new Media(Convert.ToInt32(pic.Value));
                       
    picture.ImageUrl = picMedia.getProperty("umbracoFile").Value.ToString();

     

    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

Please Sign in or register to post replies

Write your reply to:

Draft