Search
Categories
  ASP.NET
Visual C#
Visual Basic
.NET Framework
ADO.NET
AJAX
LINQ
Java
 
Tutorial Rating
 
2.5 out of 5


Total Votes: 22
         
1 2 3 4 5
 




How to use DriveInfo class in .NET 2.0

Author: Waqas Anwar - Posted Date: 02-March-2008 - Category: .NET Framework   
Bookmark and Share
One of the most common task developers perform in everyday programming is to Working with the file system. This task includes navigating drives, folders and files and get some useful information for the front end application. System.IO namespace in .NET Framework 2.0 provides many classes to work with the file system. One of the class is DriveInfo class. This class represents a drive in the file system.
 

The following code demonstrates how you can get all the drives of the system using DriveInfo class static/shared method GetDrives() which returns an array of DriveInfo objects.


C#

DriveInfo[] drives = DriveInfo.GetDrives();

foreach (DriveInfo drive in drives)
{
    if (drive.IsReady)
    {
        Console.WriteLine(drive.AvailableFreeSpace);
        Console.WriteLine(drive.DriveFormat);
        Console.WriteLine(drive.RootDirectory);
        Console.WriteLine(drive.TotalFreeSpace);
        Console.WriteLine(drive.TotalSize);
        Console.WriteLine(drive.VolumeLabel);
    }               
}


VB.NET

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

For Each drive As DriveInfo In drives
    If drive.IsReady Then
        Console.WriteLine(drive.AvailableFreeSpace)
        Console.WriteLine(drive.DriveFormat)
        Console.WriteLine(drive.RootDirectory)
        Console.WriteLine(drive.TotalFreeSpace)
        Console.WriteLine(drive.TotalSize)
        Console.WriteLine(drive.VolumeLabel)
    End If
Next



RELATED TUTORIALS

  Using DriveInfo class in VB.NET to get System Drives Information
  How to get System Drives Information in C# using DriveInfo class

LEAVE YOUR COMMENTS LEAVE YOUR COMMENTS
 Name (required)  
 Email (required
 Website


 
POSTED COMMENTS POSTED COMMENTS

hi everyone
I don't know how I can solve the problem while I want to read the removeable drive because all of them they are not ready so how I can read volumeLable.
Posted by Kamyar on Thursday, February 05, 2009

AOA
thanks sir
your site is a wonderful work and made something easy for me.

not confusions in it.
Posted by mehood ahmed on Thursday, May 28, 2009

 


 
 
 

Categories

My Portfolio

Website Links


Copyright @ 2009 EzzyLearning.com