To augment Alex's comments, Phong, here's a little helper function I use that saves me a line of two of code in the view, and also guards against null pointers.
Can't take credit for this, as I think I found something similar to it elsewhere in this forum :)
public static string GetMediaUrl(string mediaId, UmbracoHelper uHelper)
{
var itemUrl = "";
var mediaItem = uHelper.TypedMedia(mediaId);
if (mediaItem != null)
{
itemUrl = GetItemUrl(mediaItem);
}
return itemUrl;
}
// Used by both GetMediaUrl (above) and GetContentUrl (below)
public static string GetItemUrl(IPublishedContent content)
{
string url = content != null ? content.Url : "";
return url;
}
// Like GetMediaUrl, but uses TypedContent for document types
public static string GetContentUrl(string contentId, UmbracoHelper uHelper)
{
var itemUrl = "";
var contentItem = uHelper.TypedContent(contentId);
if (contentItem != null)
{
itemUrl = GetItemUrl(contentItem);
}
return itemUrl;
}
Thank you very much for your replies, i really appreciate your help in resolving my question.
Sorry for my late reply. I figured it out myself tomorrow, this is the code i used and It worked like a charm:
var metaImage = CurrentNode.GetPropertyValue<string>("bannerImage");
var imageUrl = "http://" + HttpContext.Current.Request.Url.Host + Umbraco.TypedMedia(int.Parse(metaImage)).GetCropUrl("Crop Alias");
I think Alex Skrypnyk's way is great but my question's mean i want to get the url include the domain name of the site. (Sorry for my miss-information question, my english is not good enough).
Anyway, thank you guys again, i love this community.
Get MediaUrl
Hi guys, I'm newbie in umbraco and i want to ask :
Is there any property that we can get url from Media? Take a look at my attachment:
Thank you very much. Regard, Phong.
Hi Phong,
Welcome to the best community in the world!
It's very easy to get media URL.
Do you want to get media URL in Razor code?
Example how to do it:
Thanks,
Alex
To augment Alex's comments, Phong, here's a little helper function I use that saves me a line of two of code in the view, and also guards against null pointers.
Can't take credit for this, as I think I found something similar to it elsewhere in this forum :)
Hi Jeff,
Thank you for code example, but can you share "GetItemUrl" method also?
Because this code isn't all
Thanks,
Alex
Thanks for pointing that out. It looks like Phong has found the solution, but I edited my answer just to be thorough.
Hi Alex Skrypnyk and Jeff Subat,
Thank you very much for your replies, i really appreciate your help in resolving my question.
Sorry for my late reply. I figured it out myself tomorrow, this is the code i used and It worked like a charm:
I think Alex Skrypnyk's way is great but my question's mean i want to get the url include the domain name of the site. (Sorry for my miss-information question, my english is not good enough).
Anyway, thank you guys again, i love this community.
Thanks,
Phong.
Hi Phong,
Thank you very much for sharing the solution!!!
Have a nice day!!!
Thanks,
Alex
is working on a reply...