Getting Disk Information using DriveInfo in C#

Hi all,

I'm going to display all disk's information (VolumeLable, File System, Total Space, FreeSpace ...etc). Here is the code...check it out.


private void Form1_Load(object sender, EventArgs e)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
Label lbl;
int i = 0;
foreach (DriveInfo d in allDrives)
{
lbl = new Label();
lbl.AutoSize = true;
lbl.Text = "Drive: " + d.Name.Substring(0,1) + "\n";
lbl.Text = lbl.Text + "FileType: " + d.DriveType + "\n";
if (d.IsReady)
{
lbl.Text = lbl.Text + "Volume label: " + d.VolumeLabel+ "\n";
lbl.Text = lbl.Text + "File system: " + d.DriveFormat + "\n";
lbl.Text = lbl.Text + "Available space to current user: " + d.AvailableFreeSpace + "bytes\n";
lbl.Text = lbl.Text + "Total available space: " + d.TotalFreeSpace + "\n";
lbl.Text = lbl.Text + "Total size of drive: " + d.TotalSize + "\n";
}
lbl.Top = i;
this.Controls.Add(lbl);
i = i + 110;
}
}


That's it...

...S.VinothkumaR.

No comments: