disk space progress bar

K

koosh34

I want to add a progress bar control on to a form that shows how much space
is being used up on the drive the application is running on.
How do I find out in the how big the disk is and how much space is being
used so I can set the progress bar correctly?
 
K

kimiraikkonen

I want to add a progress bar control on to a form that shows how much space
is being used up on the drive the application is running on.
How do I find out in the how big the disk is and how much space is being
used so I can set the progress bar correctly?

Koosh,
Though you may get free and total disk space using WMI or Win32 API,
in .NET 2.0 "My" namespace provides great way of access to these
values:

Place a progress bar on your form:

' Assign progressbar's maximum value to total size
' of the drive. I'm dividing value by 1000 to fit the value
' within integer range what progressbar accepts
ProgressBar1.Maximum =
My.Computer.FileSystem.GetDriveInfo("c:").TotalSize \ 1000

' Same way to get free space
' Dividing by 1000 not to get an arithmetic overflow
' exception
ProgressBar1.Value =
My.Computer.FileSystem.GetDriveInfo("c:").TotalFreeSpace \ 1000

Remember that, if you don't fit the byte value of the drive with
integer value range of progressbar by dividing disk space 100 or 1000
or more, you get an
"Arithmetic operation resulted in an overflow." exception due to
integer range of progress bar's value type

Tested and works with fixed drives(plus flash drives), couldn't get it
work with optical drive's such as CD-RWs.

Regards,

Onur Güzel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top