How to set file size in grid view

Total Post:108

Points:756
 1126  View(s)
Ratings:
Rate this:

I need help setting the size of flies in a grid-view, this first set of code works

protected string DisplaySize(long? size)
{
    if (size == null)
        return string.Empty;
    else
    {
        if (size <1024)
        {
            return string.Format("{0:#} bytes", size.Value);
        }
        else
        {
            return String.Format("{0:#} KB", size.Value / 1024);
        }
    }

When I try to add more values it dose not work I just get blank values 

protected string DisplaySize(long? size)
{
    if (size == null)
        return string.Empty;
    else
    {
        if (size < 1024)
        {
            return string.Format("{0:#} bytes", size.Value);
        }
        else if(size < 10240)
        {
            return String.Format("{0:#} KB", (size.Value / 1024));
        }
        else if(size < 102400)
        {
            return String.Format("{0:#} MB", (size.Value / 1024 / 1024));
        }
        else
        {
            return String.Format("{0:#} GB", (size.Value / 1024 / 1024 / 1024));
        }
    }
}
  1. Post:378

    Points:2694
    Re: How to set file size in grid view

    Hi John,


    Try the below code:

    if (size < 1024)
                {
                    return string.Format("{0:#} bytes", size.Value);
                }
                else if(size < 1048576)
                {
                    return String.Format("{0:#} KB", (size.Value / 1024));
                }
                else if(size < 1073741824)
                {
                    return String.Format("{0:#} MB", ((size.Value / 1024) / 1024));
                }
                else
                {
                    return String.Format("{0:#} GB", (((size.Value / 1024) / 1024) / 1024));
                }

      Modified On Apr-06-2018 11:36:40 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!