March 27, 2009

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




If 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:

C#


// Add namespace System.IO;


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);


    }


}




VB.NET


    ' Add namespace System.IO;


    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 di




'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

0 Responses to "List the Drives on your Computer using C# or VB.NET"
 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions