Copied to clipboard

Flag this post as spam?

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


  • Manfred Ramoser 2 posts 22 karma points
    Mar 22, 2012 @ 08:07
    Manfred Ramoser
    0

    Problems with GetMediaUrl

    Hello,

    I am trying to show mediaitems on a page which are stored on the content type as "Bild" which is an upload property. To do so I am using the following code:

    <img alt="Bild zum Artikel" src="@Umbraco.GetMediaUrl(@item.Id"bild")"/>

    This works until I have an item which has no picture set. Then I get the following exception:

    Exception Details: System.UriFormatException: Invalid URI: The hostname could not be parsed.

    To avoid this problem I tried the following:

    if (new HiveId(item.Bild) != HiveId.Empty)
        {
     <img alt="Bild zum Artikel" src="@Umbraco.GetMediaUrl(@item.Id"bild")"/>
        }

    But the condition is always true and the error appears again. I tried to print out this:

    <p>@(new HiveId(item.Bild))</p>
    <p>@(new HiveId(item.Bild.Id))</p>

    But the result is always: string$_

    Am I missing something or is it a bug?

    I use Umbraco 5 with Razor.

     

  • Tv 2 posts 22 karma points
    Mar 27, 2012 @ 23:31
    Tv
    0

    Ran into the same issue today, so same question here. How do you check if a file/image is uploaded or not in Umbraco 5 with Razor?

    I have "umbraco devdataset package" installed. Just removed an image under the "books" section. Same problem. Apparently there's no check to see if an image is uploaded or not in this package, so a code example would be nice :)

    Thx.

  • Michael Perry 11 posts 43 karma points
    Apr 13, 2012 @ 16:50
    Michael Perry
    0

    I am also experiencing the same issue described here.  There has to be a way to check if an image/file is uploaded, or Umbraco.GetMediaUrl should be able to fail gracefully when no file/image exists.

Please Sign in or register to post replies

Write your reply to:

Draft