Want to build the ChatGPT based Apps? Start here
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Abhilash J A
813
2.4k
549.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 ?
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]);
}
Reply
Answers (
8
)
why we are using file io in c#
Rounding off Decimal Digits