Copied to clipboard

Flag this post as spam?

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


  • Petras Surna 90 posts 144 karma points
    Apr 06, 2011 @ 07:06
    Petras Surna
    0

    How do you get a Media Image URL without c# code?

    I want to get a simple URL of a media image in Razor.

    How do you do this?

    I had to resort to c# code which seems like an overkill:

     @MediaFunctions.GetURL(1099)

    which called

      public class MediaFunctions
      {
        public static string GetURL(int mediaId)
        {
          string url = "";

          var media = new umbraco.cms.businesslogic.media.Media(mediaId);
          var file = media.getProperty("umbracoFile");
          url = (string)file.Value;

          return url;
        }

    Is there a way to do it without calling custom code?

  • Toni Becker 146 posts 425 karma points
    Apr 06, 2011 @ 07:21
    Toni Becker
    0

    Can you show your xml form umbraco.config inside your App_Data Folder?

    you could easily access the umbracoFile with the . notation

    <img src="@Model.anotherNode.yourProperty.umbracoFile" />

  • Sebastiaan Janssen 5045 posts 15476 karma points MVP admin hq
    Apr 06, 2011 @ 07:30
    Sebastiaan Janssen
    2

    You can do this easily with :

    <img src="@Model.MediaById(1099).umbracoFile" />
  • Toni Becker 146 posts 425 karma points
    Apr 06, 2011 @ 07:35
    Toni Becker
    0

    or this way :)

  • Petras Surna 90 posts 144 karma points
    Apr 06, 2011 @ 08:03
    Petras Surna
    1

    Woo hoo

    @Model.MediaById(1099).umbracoFile

    that works!

Please Sign in or register to post replies

Write your reply to:

Draft