0

Possible Duplicate:
How do I retrieve disk information in C#?

  • I need a .net c# code example to detect each server's drive space.
  • I also want step by step implementation instructions.
María Antignolo
  • 388
  • 4
  • 17
abc
  • 1
  • 2
    I would rather teach you to fish, than giving you a fish. Which part of logic you are not able to sort out? – Pradeep Mar 14 '11 at 11:24
  • Possible duplicate: http://stackoverflow.com/questions/412632/how-do-i-retrieve-disk-information-in-c – razlebe Mar 14 '11 at 11:25

2 Answers2

4

You can use the DriveInfo.GetDrives method to retrieve an array of logical drives on a machine.

Example:

var nameAndFreeSpaceOfDrives = from drive in DriveInfo.GetDrives()
                               where drive.IsReady
                               select new { drive.Name, drive.TotalFreeSpace };
Ani
  • 111,048
  • 26
  • 262
  • 307
2

You also can use management objects to obtain free space:

        using System.Management;
        .........
        ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
        disk.Get();
        MessageBox.Show(disk["FreeSpace"] + " bytes");

You also have to add reference to System.Management assembly manualy

Anton Semenov
  • 6,227
  • 5
  • 41
  • 69