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:
<imgalt="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 (newHiveId(item.Bild) != HiveId.Empty)
{
<imgalt="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:
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 :)
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.
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:
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:
But the condition is always true and the error appears again. I tried to print out this:
But the result is always: string$_
Am I missing something or is it a bug?
I use Umbraco 5 with Razor.
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.
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.
is working on a reply...