Abhilash J A

Abhilash J A

  • 533
  • 2.4k
  • 598.2k

How can I get total size of File in MB or KB etc... ?

Jan 5 2017 3:05 PM
Hello Everyone,
 
I have list of items to bind listview wpf. Inside list items there is  FileSize = FormatBytes(x.fsize) I want to get total size of FileSize. How can I do that ?
 
  
  1. public UC_ArcMgmt()  
  2.        {  
  3.            InitializeComponent();  
  4.            DMSBusinessLayer service = new DMSBusinessLayer();  
  5.            var data = service.GetArchivedList().SelectMany((x) => new[] { new { Fullname = x.Fullname, Id = x.Id, ArchievedName = x.ArchievedName, UpdatedDate = x.UpdatedDate, FileSize = FormatBytes(x.fsize), docCount = x.docCount } }).Distinct()  
  6. GroupBy((x) => x.ArchievedName);  
  7.            List<Tble_Documents> objTble_Documents = new List<Tble_Documents>();  
  8.            foreach (var x in data)  
  9.            {  
  10.                objTble_Documents = x.AsEnumerable().Select(m => new Tble_Documents()  
  11.                    {  
  12.                        Fullname = m.Fullname,  
  13.                        Id = m.Id,  
  14.                        ArchievedName = m.ArchievedName,  
  15.                        UpdatedDate = m.UpdatedDate,  
  16.                        FilePath = m.FileSize,  
  17.                        docCount = m.docCount  
  18.                    }).ToList();  
  19.            }  
  20.            listView1.ItemsSource = objTble_Documents;  
  21.        }  
  22.   
  23.        private static string FormatBytes(long bytes)  
  24.        {  
  25.            string[] Suffix = { "B""KB""MB""GB""TB" };  
  26.            int i;  
  27.            double dblSByte = bytes;  
  28.            for (i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024)  
  29.            {  
  30.                dblSByte = bytes / 1024.0;  
  31.            }  
  32.            return String.Format("{0:0.##} {1}", dblSByte, Suffix[i]);  
  33.        }  
 

Answers (8)