7

The title pretty much says it all. I feel like I've come across a method in the past that does something like:

long fileSize = 524288000;
string prettyFileSize = Sitecore.SomeUtility.ConvertPrettyFileSize(fileSize);

Resulting in prettyFileSize containing "512MB".

13

You are correct, you probably have come across this. The Sitecore.StringUtil, Sitecore.Kernel class contains a number of methods for managing strings.

The two methods in particular are:

StringUtil.GetSizeString(long size)

This method takes in a long value 524288000, and returns a string representation of "512MB"

StringUtil.ParseSizeString(string value)

This method takes in a string value like "512MB" and returns the long representation of that size, 524288000.

An Example:

    using Sitecore;

    public long GetLongValue(string valueSize)
    {
       return StringUtil.ParseSizeString(valueSize);
    }

    public string GetStringSize(long size)
    {
       return StringUtil.GetSizeString(size);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.