Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Program to get free space in a drive
To get the free space in a drive, use the AvailableFreeSpace and TotalFreeSpace properties in C#.
Firstly, set the name of the drive using DriveInfo −
DriveInfo dInfo = new DriveInfo("D");
Let’s say, you need to find the available space for D drive −
Example
using System;
using System.Linq;
using System.IO;
public class Demo {
public static void Main() {
DriveInfo dInfo = new DriveInfo("D");
// Get free space
Console.WriteLine(dInfo.AvailableFreeSpace);
// get total free space
Console.WriteLine(dInfo.TotalFreeSpace);
}
}
Output
The following is the output showing the free space available in D drive−
722243567912 722243567912
Advertisements
