Thanks for the response. I can't figure out however how to display either KB or MB.
var bytes = @file.umbracoBytes; var x = ((Convert.ToInt64(@file.umbracoBytes) / 1024).ToString() + " KB"); var y = ((Convert.ToInt64(@filef.umbracoBytes) / 1048576).ToString() + " MB");
UmbracoBytes
HI All,
Can someone explain how to display fileSize in Razor??
Same as you would do in XSLT.
Any Suggestions?
//fuji
Hi.
You can get the fileSize in Bytes with:
@Model.Media("image","umbracoBytes")
so.. it could be something like this:
@{
int bytes = int.Parse(Model.Media("image","umbracoBytes"));
int inMB = bytes / 1048576
int inKB = bytes / 1024
}
Hope that help. cheers
Hi Gilad,
Thanks for the reply but nope didnt get this working. This is how my codes looks like atm
Am getting the right fileSize but somehow i need to round it up to KB or MB
I had the same problem. Int.Parse doesn't seem to work, but this does:
var x = ((Convert.ToInt64(@file.umbracoBytes) / 1024).ToString() + " Kb");
<p>Download: <a href="@file.umbracoFile" target="_blank">@x</a></p>
Hi Dirk,
Thanks for the response. I can't figure out however how to display either KB or MB.
Any suggestion ??
should read
var bytes = Convert.ToInt64(@file.umbracoBytes);
for your code to work (also you can skip all the @varname all over the place)
so it should end up reading
Another improvement: using the "round" function and decimals to get a more accurate estimation of the file-size.
Thanks to both of you for the response @scott @Dirk.
However i have combined both solution, converting most of xslt to razor file!!
//fuji
You can use the linkSize variable where ever you need to print the doc size
is working on a reply...