Determine available disk space
Posted on 2004-10-03
Before creating a new database I'd like to check if there's enough available disk space in the drive of the directory selected by the user to create the database in.
I have a sub that determines the root of the directory selected by the user.
I have have found in MSDN the following code to return the available disk space:
Public Function GetDiskSpace() As System.UInt64
Dim diskClass As _
Dim disks As System.Management.ManagementObjectCollection = _
Dim disk As System.Management.ManagementObject
Dim space As System.UInt64
For Each disk In disks
If CStr(disk("Name")) = "C:" Then
space = CType(disk("FreeSpace"), System.UInt64)
However an exception is raised saying that "The property requested ("Name") does not exist".
They do say in MSDN that such an exception may be raised but they don't say why and what to do about it!
Any help shall be appreciated from the VB.NET beginner that I am.