How to get complete details of all Drives on the system
By Kalit Sikka
How to get complete details of all Drives on the system
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WinApps
{
public partial class Form1 : Form
{
/************************************************
* Topic : How to get complete details of all Drives on the system
* Reference Required: System.IO
* Author : kalit sikka
* For : http://eggheadcafe.com
* **********************************************/
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = FormTitle;
BindComboWithDrives();
}
///
/// Filling Combo with Drive names
///
private void BindComboWithDrives()
{
DriveInfo[]
di = DriveInfo.GetDrives();
foreach (DriveInfo itemDrive in di)
{
cboDrive.Items.Add(itemDrive.Name);
}
cboDrive.SelectedIndex=0;
}
///
/// Filling Drive info into RichTextbox control
///
///
///
private void cboDrive_SelectedIndexChanged(object sender, EventArgs e)
{
rtbDetails.Clear();
DriveInfo
di = new DriveInfo(cboDrive.SelectedItem.ToString());
rtbDetails.Text
= string.Format("Available Free Space: " + di.AvailableFreeSpace + "\n" +
"Drive Format: " + di.DriveFormat + "\n" +
"Drive Type: " + di.DriveType + "\n" +
"Is Ready: " + di.IsReady.ToString() + "\n" +
"Name: " + di.Name + "\n" +
"Root Directory: " + di.RootDirectory + "\n" +
"ToString() Value: " + di.ToString() + "\n" +
"Total Free Space: " + di.TotalFreeSpace + "\n" +
"Total Size: " + di.TotalSize + "\n" +
"Volume Label: " + di.VolumeLabel.ToString(), di.Name +
" DRIVE INFO");
}
private string FormTitle
{
get
{
return "Drive Info - Demo App for eggheadCafe.com";
}
}
}
}
Popularity (1075 Views)