开发者

.net c# code for detecting space on server for each drive [duplicate]

开发者 https://www.devze.com 2023-02-16 12:53 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How do I retrieve disk information in C#?
This question already has answers here: Closed 11 years ago.

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.


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 };


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

0

精彩评论

暂无评论...
验证码 换一张
取 消