Export (0) Print
Expand All

DriveInfo.VolumeLabel Property

Gets or sets the volume label of a drive.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public Property VolumeLabel As String

Property Value

Type: System.String
The volume label.

ExceptionCondition
IOException

An I/O error occurred (for example, a disk error or a drive was not ready).

DriveNotFoundException

The drive is not mapped or does not exist.

SecurityException

The caller does not have the required permission.

UnauthorizedAccessException

The volume label is being set on a network or CD-ROM drive.

-or-

Access to the drive information is denied.

The label length is determined by the operating system. For example, NTFS allows a volume label to be up to 32 characters long. Note that Nothing is a valid VolumeLabel.

The following example demonstrates the use of the DriveInfo class to display information about all the drives on the current system.

Imports System
Imports System.IO

Class Test
    Public Shared Sub Main()
        Dim allDrives() As DriveInfo = DriveInfo.GetDrives()

        Dim d As DriveInfo
        For Each d In allDrives
            Console.WriteLine("Drive {0}", d.Name)
            Console.WriteLine("  File type: {0}", d.DriveType)
            If d.IsReady = True Then
                Console.WriteLine("  Volume label: {0}", d.VolumeLabel)
                Console.WriteLine("  File system: {0}", d.DriveFormat)
                Console.WriteLine( _
                    "  Available space to current user:{0, 15} bytes", _
                    d.AvailableFreeSpace)

                Console.WriteLine( _
                    "  Total available space:          {0, 15} bytes", _
                    d.TotalFreeSpace)

                Console.WriteLine( _
                    "  Total size of drive:            {0, 15} bytes ", _
                    d.TotalSize)
            End If 
        Next 
    End Sub 
End Class 
'This code produces output similar to the following: 

'Drive A:\ 
'  File type: Removable 
'Drive C:\ 
'  File type: Fixed 
'  Volume label:  
'  File system: FAT32 
'  Available space to current user:     4770430976 bytes 
'  Total available space:               4770430976 bytes 
'  Total size of drive:                10731683840 bytes  
'Drive D:\ 
'  File type: Fixed 
'  Volume label:  
'  File system: NTFS 
'  Available space to current user:    15114977280 bytes 
'  Total available space:              15114977280 bytes 
'  Total size of drive:                25958948864 bytes  
'Drive E:\ 
'  File type: CDRom 

'The actual output of this code will vary based on machine and the permissions 
'granted to the user executing it.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft