Get System Drives Information in C# using DriveInfo class

You are currently viewing Get System Drives Information in C# using DriveInfo class

DriveInfo class in .NET Framework is very useful class you can use to get information about the system drives. It has many properties and methods to query drive information such as drive type, drive format, total size or total free space. In the following Tutorial I will show you how to use this class in .NET Windows Application.

private void Form1_Load(object sender, EventArgs e)
{
      DriveInfo[] drives = DriveInfo.GetDrives();
      foreach (DriveInfo drive in drives)
      {
            this.comboBox1.Items.Add(drive.Name); 
      }
}

private void button1_Click(object sender, EventArgs e)
{
      string driveName = comboBox1.SelectedItem.ToString();
      DriveInfo drive = new DriveInfo(driveName);

      label2.Text = "Drive Name: " + drive.Name;
      label3.Text = "Volume Label: " + drive.VolumeLabel;
      label4.Text = "Drive Type: " + drive.DriveType.ToString();
      label5.Text = "Drive Format: " + drive.DriveFormat;
      label6.Text = "Total Size: " + (drive.TotalSize/1024/1024/1024) + " GB" ;
      label7.Text = "Free Disk Space: " + (drive.TotalFreeSpace / 1024 / 1024 / 1024) + " GB";
      label8.Text = "Drive Ready: " + drive.IsReady.ToString();
}
READ ALSO:  Using SqlConnectionStringBuilder class in C#

This Post Has 2 Comments

  1. ali amini

    many thanks.

  2. adil

    fantastic if it works……………..

Leave a Reply