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");
}
}This code snippet is for to get the disk information in C#.
