Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Get The Disk Information In C#
WhatsApp
Apurba Ranjan
Aug 20
2016
3.1
k
0
0
DriveInfo[] allDrives = DriveInfo.GetDrives();
dataGridView1.Columns.Add(
"Name"
,
"Name"
);
dataGridView1.Columns.Add(
"DriveType"
,
"Drive Type"
);
dataGridView1.Columns.Add(
"VolumeLabel"
,
"Volume Label"
);
dataGridView1.Columns.Add(
"DriveFormat"
,
"Drive Format"
);
dataGridView1.Columns.Add(
"AvailableFreeSpace"
,
"Available Free Space"
);
dataGridView1.Columns.Add(
"TotalFreeSpace"
,
"Total Free Space"
);
dataGridView1.Columns.Add(
"TotalSize"
,
"Total Size"
);
foreach (DriveInfo d in allDrives)
{
if
(d.IsReady ==
true
)
{
double
AFS =Math.Round( (Convert.ToDouble(d.AvailableFreeSpace) /
1024
) /
1024
/
1024
);
double
TFS = Math.Round((Convert.ToDouble(d.TotalFreeSpace) /
1024
) /
1024
/
1024
);
double
TS = Math.Round((Convert.ToDouble(d.TotalSize) /
1024
) /
1024
/
1024
);
dataGridView1.Rows.Add(d.Name, d.DriveType, d.VolumeLabel, d.DriveFormat, AFS+
" GB"
, TFS +
" GB"
, TS +
" GB"
);
}
}
Disk Information
C#
Up Next
How To Get The Disk Information In C#