Q:

How to calculate free disk space?

I'm working on an installer project where I need to extract files to the disk. How can I calculate/find the disk space available on hard disk using c#?

A:

Use the System.IO.DriveInfo class. There are two options available...one that takes disk quotas into account:
var drive = new DriveInfo("c");
long freeSpaceInBytes = drive.AvailableFreeSpace;

and one that simply provides the total free space:
var drive = new DriveInfo("c");
long freeSpaceInBytes = drive.TotalFreeSpace;

A:

http://msdn.microsoft.com/en-us/library/system.io.driveinfo.totalfreespace.aspx
Copied from the link
using System;
using System.IO;

class Test
{
    public static void Main()
    {
        DriveInfo[] allDrives = DriveInfo.GetDrives();

        foreach (DriveInfo d in allDrives)
        {
            Console.WriteLine("Drive {0}", d.Name);
            Console.WriteLine("  File type: {0}", d.DriveType);
            if (d.IsReady == true)
            {
                Console.WriteLine("  Volume label: {0}", d.VolumeLabel);
                Console.WriteLine("  File system: {0}", d.DriveFormat);
                Console.WriteLine(
                    "  Available space to current user:{0, 15} bytes", 
                    d.AvailableFreeSpace);

                Console.WriteLine(
                    "  Total available space:          {0, 15} bytes",
                    d.TotalFreeSpace);

                Console.WriteLine(
                    "  Total size of drive:            {0, 15} bytes ",
                    d.TotalSize);
            }
        }
    }
}

