Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Getting information about Drives on a system using the new DriveInfo class in .NET 2.0

Author: Aadil

In this article I’ll try to explain the features of the new DriveInfo class in the System.IO namespace in the new .NET Framework 2.0

In this article I’ll try to explain how you can get information about the drives present on a system and further their detailed properties using the new DriveInfo class. This class is an addition in the .NET Framework 2.0 and provides the benefits of getting drive information like the name of the drive letter, available space etc.

 

First of all there is a shared method of DriveInfo class called GetDrives that returns an array of DriveInfo objects representing all the available drives in the system. You can then iterate this array using a for each loop and get information about each drive. There are some very interesting properties like AvailabeFreeSpace that returns the available free space present on this drive. The DriveFormat property gives you the type of file system on the specific drive like the FAT32 or NTFS file system.

 

The DriveType property of DriveInfo class is a type of DriveType enumeration that contains values like CDROM , Network, Removable that represent the physical type of this drive. IsReady tells you weather this drive is ready for some operation. The floppy drive can be checked for this property and then worked with. Name property gives you the friendly name for this drive. TotalFreeSpace and TotalSize properties are self explanatory and serves the purpose of getting to know about the available space and total space of this drive.

 

I’ve created a simple function that iterates over all drives and gets the property of each one in separate variables. You can use these variables to display information either on console of on some component like a textbox.

 

Here is the code

 

foreach (DriveInfo dinf in DriveInfo.GetDrives())

{

long lngFreeSpace = dinf.AvailableFreeSpace;

long strDriveFormat = dinf.DriveFormat;

DriveType dt = dinf.DriveType;

bool blnReady = dinf.IsReady;

DirectoryInfo rootDir = dinf.RootDirectory;

long freeSpace = dinf.TotalFreeSpace;

long totalSize = dinf.TotalSize;

string strVolumeLabel = dinf.VolumeLabel;

}

Article Comments
I WANT TO KNOW ABT ASP.NET AND UPS DRIVE AND ALSO RELATED WITH THE EVERY TYPE OF COMPUTER HARDWARE DRIVE

Posted on 4/19/2007 10:40:54 AM by KRUNAL

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Boxing and Un-Boxing in C#

Disclaimer - Privacy
© 2002-2017 DevASP.net