Mega Code Archive

 
Categories / C# / File Stream
 

Gets the file size text

// //------------------------------------------------------------------------------ // // <copyright file="" company="Dascoba Development"> // //  Copyright Â© Dascoba Development 2010 // // </copyright> // //------------------------------------------------------------------------------ namespace Dascoba.Umb.FileManager.Support {     using System;     using System.IO;     using System.Linq;     public static class Util     {         /// <summary>         ///   Gets the file size text.         /// </summary>         /// <param name = "sizeInBytes">The size in bytes.</param>         /// <returns></returns>         internal static string GetFileSizeText(long sizeInBytes)         {             var sizeText = sizeInBytes + " Bytes";             if (sizeInBytes > 1024 && sizeInBytes < 1048576)             {                 sizeText = (sizeInBytes / 1024) + " KB";             }             if (sizeInBytes > 1048576 && sizeInBytes < 1073741824)             {                 sizeText = (sizeInBytes / 1024 / 1024) + " MB";             }             if (sizeInBytes > 1073741824 && sizeInBytes < 1099511627776)             {                 sizeText = (sizeInBytes / 1024 / 1024) + " GB";             }             return sizeText;         }     } }