namespace WinFormsApp1
{
public partial class Form1 : Form
{
private long GetTotalFreeSpace(string driveName)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == driveName)
{
return drive.TotalFreeSpace;
}
}
return -1;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = string.Format("{0:n}", GetTotalFreeSpace("C:\\") / 1024.0 / 1024.0) + " MB Free";
}
}
}
/*
* run:
*
* 512,198.52 MB Free
*
*/