开发者

How do I get the absolute media file path in umbraco using razor?

开发者 https://www.devze.com 2023-03-26 19:08 出处:网络
I\'ve tried the following bit of razor code: @room.Media(\"summaryImage\",\"umbracoFile\") but I get something like ~/media/155/lux.jpg, how do I remove the initial ~ to get a server path ie, /medi

I've tried the following bit of razor code:

@room.Media("summaryImage","umbracoFile")

but I get something like ~/media/155/lux.jpg, how do I remove the initial ~ to get a server path ie, /media/155/lux.jpg or http://some_url/media/155/lux.jpg?

EDIT:

I've tried

@{
  dynamic summaryImagePath = room.Media("summaryImage","umbracoFile");
}
@Page.ResolveUrl(@summaryImagePath)

and

@Page.ResolveUrl(@room.Media("su开发者_如何学PythonmmaryImage","umbracoFile"))

but I keep getting the error:

Error loading Razor Script Cannot perform runtime binding on a null reference

even though @room.Media("summaryImage","umbracoFile") gives ~/media/155/lux.jpg.

Any ideas?


I'm not sure whether there is a solution within Umbraco, I'd just use the .NET framework. With ASP.NET, you can use MapPath to resolve virtual paths to physical file paths:

@HttpContext.Current.Server.MapPath(room.Media("summaryImage","umbracoFile"))

EDIT:

If you are looking for the absolute URL, you may use one of the following variants:

@Page.ResolveUrl(room.Media("summaryImage","umbracoFile"))

or

@VirtualPathUtility.ToAbsolute(room.Media("summaryImage","umbracoFile"))

You may would like to read this article about different approaches for resolving URLs.

0

精彩评论

暂无评论...
验证码 换一张
取 消