Selected a USB flash drive by default

  • Thread starter Thread starter Dustin Davis
  • Start date Start date
D

Dustin Davis

This might be a pipe dream, but here goes...

I'm writing an application many users will be working on and saving
files to USB flash drives. When they click the save button, I would like
to have the default save path be the flash drive, if one exists. The
best solution I can thing of is to assume the drive will be E:\ and put
that in a Try/Catch to have that be the default path.

Does anyone know of a better solution that this can be accomplished in
VB.NET?

(I'm using VB.NET 2005)

Thanks,
Dustin
 
Hi Dustin,

Not a pipe dream at all. In the System.IO namespace there are classes for
enumerating available drives on the machine. You can check the properties
of each drive and I think you should be able to tell from those properties
whether it's a removable drive. Failing that, start looking into the WMI
classes as they will undoubtedly have the power to determine the exact spec
of all available drives on the machine.

Cheers,
Alex Clark
 
Wow - Awesome, thanks for the info!

Alex said:
Hi Dustin,

Not a pipe dream at all. In the System.IO namespace there are classes for
enumerating available drives on the machine. You can check the properties
of each drive and I think you should be able to tell from those properties
whether it's a removable drive. Failing that, start looking into the WMI
classes as they will undoubtedly have the power to determine the exact spec
of all available drives on the machine.

Cheers,
Alex Clark
 
Thanks again Alex. It works great. Here's the code in case anyone else
is interested:

' Find the first removable storage device and make this the initial
' directory if it exists
Dim allDrives() As IO.DriveInfo = IO.DriveInfo.GetDrives()
Dim d As IO.DriveInfo
For Each d In allDrives
If d.IsReady = True AndAlso d.DriveType = IO.DriveType.Removable Then
Me.SaveFileDialog1.InitialDirectory = d.Name
End If
Next
 
Thank you Dustin for the code. (I think you need an exit for, if you
mean to catch the first one :)

But actually, I have another problem, I have been trying this code om
my 2 usb drives (Avixe 1Gb, Arcdisk 4Gb). Strangely the Arcdisk, is not
reported as "Removable" in the DriveInfo but as "Fixed". Strange eh?
Does anyone have an explanation for that. One difference beetween the 2
USB drives, apart the size, is that I have formatted Arcdisk as NTFS
while the other is FAT. Can this be a reason ?? Or is this a bug of
DriveInfo.GetDrives ?

Dustin Davis ha scritto:
 
Thank you Dustin for the code. (I think you need an exit for, if you
mean to catch the first one :)

Acutally, I wanted the last one, since the first one will normally be
the A:\ drive.

I'm not sure why your other drive would say fixed. That is interesting!
 
Back
Top