Don't think there is a managed class to do this but you can easily use the API.
internal static class Win32
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern bool GetDiskFreeSpaceEx(string drive, out long freeBytesForUser, out long totalBytes, out long freeBytes);
}
Inside your form access the API as follows: (UNC path is in textBox1):
private void button1_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(textBox1.Text))
{
string pathName = textBox1.Text;
long freeBytesForUser, totalBytes, freeBytes;
if (Win32.GetDiskFreeSpaceEx(pathName, out freeBytesForUser, out totalBytes, out freeBytes))
{
label1.Text = String.Format("Free Space (user): {0}\nFree Space (total): {1}\nTotal Space: {2}",
freeBytesForUser,
freeBytes,
totalBytes);
}
else
{
string errorMessage = String.Format("Unable to obtain free space. Error #{0}.", Marshal.GetLastWin32Error());
MessageBox.Show(errorMessage);
}
}
}
Hope that's what you're looking for.
