@{
var mediaItemUrl = string.Empty;
if(Model.Content.HasValue("sampleChapterFile")){
mediaItemUrl = Umbraco.TypedMedia(Model.Content.GetPropertyValue("sampleChapterFile")).GetPropertyValue("umbracoFile");
}
}
Further down
@{
if (!string.IsNullOrEmpty(mediaItemUrl){
Do something with @mediaItemUrl
}
}
Get File URL from property
Hi there
i seem to be able to retrive a numeric value from a mdia picker property, but what i need is the actual url to the file
can anyonew help? - here is my code
if(Model.Content.GetPropertyValue("sampleChapterFile").ToString()!= null)
{
sampleChapterFile = Model.Content.GetPropertyValue("sampleChapterFile").ToString();
}
cheers
Nic
Hi Nic,
Take a look at the example in the documentation here
Jeavon
Hi Jeavon
Thanks for that
How can i set the url value to a variable in my code and then use it in the page below?
The value will not always exist
cheers
Nic
Hi Nic,
How about
Jeavon
thanks for that, what if the i need to pull the value back in a loop, like the below:
@foreach(var article in Model.Content.Children().Where(c => c.DocumentTypeAlias =="Items" && c.IsVisible()).Take(maxNumArticlesToShow))
{
HtmlString details = article.GetPropertyValue<HtmlString>("details");
HtmlString thumb = article.GetPropertyValue<HtmlString>("thumbnail");
var img = string.Empty;
if (article.HasValue("thumbnail")){
var dynamicMediaItem = Umbraco.Media(Model.Content.GetPropertyValue("thumbnail"));
img = dynamicMediaItem.umbracoFile;
}
Hi Nic,
That looks fine, the img variable is local to the foreach loop, so I'm not quite sure what your are after?
Jeavon
is working on a reply...