Use of System.IO.DriveInfo class in Windows application using C#

I came across one task recently which needs interaction with windows drive. Today I finished it and thought to share one small part of that script with you. This script will simply find out all the available drive in your windows system and display its information about drive letter, drive type, free available space, format of drive. I have used C# windows application in my example so simply create one windows application, draw one button and one label on your windows form.

Once you prepare with your application, have a look at below given code which suppose to be placed in button1’s click event.

label1.Text = “”;

foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())

{

if (drive.DriveType.ToString().ToLower() == “fixed” drive.DriveType.ToString().ToLower() == “removable”)

label1.Text = label1.Text + drive.Name + “==>” + drive.DriveType + “==>” + drive.DriveFormat + “==>” + drive.AvailableFreeSpace + “\n”;

else

label1.Text = label1.Text + drive.Name + “==>” + drive.DriveType + “==>0==>0\n”;

}

So here you finished your small yet useful script.

Happy Programming!!!!

Reference: Ritesh Shah

http://www.sqlhub.com
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of
http://www.SQLHub.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: