List the Drives on your Computer using C# or VB.NET

No.of Views1243
Bookmarked0 times
Downloads 
Votes0
By  Troy   On  15 Feb 2010 23:02:08
Tag : VB.NET , How to
List the Drives on your Computer using C# or VB.NET
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction


Sometimes you want to create a program to provide information about your Computer Drive, then use the System.IO.DriveInfo class. The DriveInfo class can be used to determine the drives available on your computer, drive capacity, free space, type of drives etc. as shown below:

Technologies

.Net Framework 2.0 or later

Language

C# and VB.NET


Prerequisite

Visual Studio 2005


Implementation

C# Code


// Add namespace System.IO;


{codecitation class="brush: csharp; gutter: true;" width="500px"}

DriveInfo[] myDrives = DriveInfo.GetDrives();

foreach (DriveInfo di in myDrives)

{              

Console.WriteLine(di.Name);

if (di.IsReady)

{

Console.WriteLine(di.TotalSize);

Console.WriteLine(di.DriveFormat);

Console.WriteLine(di.AvailableFreeSpace);

Console.WriteLine(di.TotalFreeSpace);

Console.WriteLine(di.DriveType);

Console.WriteLine(di.VolumeLabel);

}

}

{/codecitation}

VB.NET Code


' Add namespace System.IO;


{codecitation class="brush: vbnet; gutter: true;" width="500px"}

Dim myDrives() As DriveInfo = DriveInfo.GetDrives()

For Each di As DriveInfo In myDrives

Console.WriteLine(di.Name)

If di.IsReady Then

Console.WriteLine(di.TotalSize)

Console.WriteLine(di.DriveFormat)

Console.WriteLine(di.AvailableFreeSpace)

Console.WriteLine(di.TotalFreeSpace)

Console.WriteLine(di.DriveType)

Console.WriteLine(di.VolumeLabel)

End If

Next

{/codecitation}

I hope this code snippet save the time to get list of drive in a machine using .NET Framework class.

Thank you

Venkat

 
Sign Up to vote for this article
 
About Author
 
Troy
Occupation-Not Provided
Company-Not Provided
Member Type-Junior
Location-Not Provided
Joined date-10 Jun 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top