TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How To Get The Disk Information In C#
Apurba Ranjan
Aug 20
2016
Code
2.6
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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#