SIGN UP MEMBER LOGIN:    
ARTICLE

DriveInfo Class in C# with an Example

Posted by Senthilkumar Articles | .NET 4.5 December 15, 2011
The DriveInfo class in the System.IO namespace provides a way to get drive details.
Reader Level:
Download Files:
 

Introduction:

The DriveInfo class in C# is one of the important classes in the System.IO namespace, since it can get the system information like drive type, the space, etc.., We will discuss this class in detail with a sample application.

How to Get the Drives:

The drives in the system can be used by the GetDrives method in the DriveInfo class. It will return a collection of DriveInfo objects.

DriveInfo[] driveInfo = DriveInfo.GetDrives();

DriverInfo1.jpg


DriveInfo Class:

The System.IO namespace has a class which helps the users to interact with the system to get the file details, directory details and system information. The DriveInfo class is a readonly class and can be used to get details about the drives.

It has the following properties in the DriveInfo class. Let us see the one by one.

DriveInfo driveInfo = new DriverInfo("Drive Name");

The drive name has to be passed as constructor to get the details about the drive in the system.

Name:

The name is one of the property in the DriveInfo class which gives the name of the drive like C or D...

DriverInfo2.jpg

DriveType:

The DriveType is enum type in the System.IO namespace and it has set of enum numbers.

         DriveType.jpg

It will give the details of type f DriveType. As you know that there are some times of drive like system drive, removable drive, cd rom...

Ready:

This is Boolean type of property which tell us whether the drive is ready or not. Because some the drive allocated for the device like removable, CD ROM. But it will be enabled when the device is plugged with the device.

TotalSize:

The total size of the drive can be manipulated based on the device state. If it is system drive then it will be ready when the OS is running. But the same time the device like Removable and CD ROW size will be manipulated only when the state is Ready. Otherwise it will not give any such details.

AvailableFreeSpace:

This is also one of the peoperty in the class and which tells the available space in the drive when the state of the device is ready.

VolumeLabel:

Every drive will have the volume label, which will be returned by the driveinfo class.

DriverInfo3.jpg

Conclusion:

The DriveInfo class is one of the very useful classes to scale the drive information. The source code attached in the article.

 

Login to add your contents and source code to this article
share this article :
post comment
 

Hi dudes, Thank you very much for reading this.

Posted by Senthilkumar Dec 18, 2011

Hi Senthilkumar. Good article.

Posted by Monika Arora Dec 18, 2011

well explained... good work..

Posted by Manoj Singh Panwar Dec 17, 2011

Nice article, Senthilkumar. It is so helpful.

Posted by Alok Pandey Dec 17, 2011

great work.

Posted by Akshay Teotia Dec 16, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Become a Sponsor