Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
8
Reply
How can I get total size of File in MB or KB etc... ?
Mani Kandan
Jan 5 2017 3:05 PM
257
Reply
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 ?
public
UC_ArcMgmt()
{
InitializeComponent();
DMSBusinessLayer service =
new
DMSBusinessLayer();
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()
GroupBy((x) => x.ArchievedName);
List<Tble_Documents> objTble_Documents =
new
List<Tble_Documents>();
foreach
(var x
in
data)
{
objTble_Documents = x.AsEnumerable().Select(m =>
new
Tble_Documents()
{
Fullname = m.Fullname,
Id = m.Id,
ArchievedName = m.ArchievedName,
UpdatedDate = m.UpdatedDate,
FilePath = m.FileSize,
docCount = m.docCount
}).ToList();
}
listView1.ItemsSource = objTble_Documents;
}
private
static
string
FormatBytes(
long
bytes)
{
string
[] Suffix = {
"B"
,
"KB"
,
"MB"
,
"GB"
,
"TB"
};
int
i;
double
dblSByte = bytes;
for
(i = 0; i < Suffix.Length && bytes >= 1024; i++, bytes /= 1024)
{
dblSByte = bytes / 1024.0;
}
return
String.Format(
"{0:0.##} {1}"
, dblSByte, Suffix[i]);
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
8
)
Next Recommended Forum
why we are using file io in c#
Rounding off Decimal Digits