Gets the file size text. : File Command « File Stream « C# / C Sharp






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;
        }

    }
}

   
    
    
    
    
  








Related examples in the same category

1.C# Implementation of the File Copy Command
2.Use the FileInfo Class to Delete Files with Ease
3.File Move Implementation
4.Rename File Name
5.Rename File Extension
6.Backup File
7.Copy directory
8.Find string in a file
9.Converts a number of bytes to a shorter, more readable string representation
10.Compares the specified file1. This method accepts two strings the represent two files to compare.
11.File Renamer
12.Format File Size
13.Is File Existed
14.Is File readable or writeable
15.Replace in file
16.Send a file to the recycle bin
17.Copy file and folder
18.Gets last write time for a file.
19.Execute File
20.Get File Bytes And Readable Size Information
21.Copy folder
22.Empty a Folder