How to get complete drive information using C#?

ProgrammingServer Side ProgrammingCsharp

Drive information of an Operating System includes.

Drive Name
Volume Label
Free Space
Total Size
Drive Format
Drive Type

To get above information about a drive, try to run the following code −

Example

using System.IO;
using System;
class Program {
   static void Main() {
      DriveInfo driveInfo = new DriveInfo("D");
      Console.WriteLine(driveInfo.Name);
      Console.WriteLine(driveInfo.VolumeLabel);
      Console.WriteLine(driveInfo.AvailableFreeSpace);
      Console.WriteLine(driveInfo.TotalFreeSpace);
      Console.WriteLine(driveInfo.TotalSize);
      Console.WriteLine(driveInfo.DriveFormat);
      Console.WriteLine(driveInfo.DriveType);
   }
}

Output

The following is the output −

D:
NTFS
76767677788
76767677788
45463434799
NTFS
Fixed

Note − The output may vary with different Operating Systems.

raja
Published on 11-Sep-2018 12:08:36
Advertisements