By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,490 Members | 3,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,490 IT Pros & Developers. It's quick & easy.

Selected a USB flash drive by default

P: n/a
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
Mar 29 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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


"Dustin Davis" <du**********@gmail.com> wrote in message
news:O2**************@TK2MSFTNGP12.phx.gbl...
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

Mar 29 '06 #2

P: n/a
Wow - Awesome, thanks for the info!

Alex Clark wrote:
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


"Dustin Davis" <du**********@gmail.com> wrote in message
news:O2**************@TK2MSFTNGP12.phx.gbl...
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


Mar 30 '06 #3

P: n/a
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

Alex Clark wrote:
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


"Dustin Davis" <du**********@gmail.com> wrote in message
news:O2**************@TK2MSFTNGP12.phx.gbl...
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


Mar 30 '06 #4

P: n/a

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:
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

Alex Clark wrote:
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


"Dustin Davis" <du**********@gmail.com> wrote in message
news:O2**************@TK2MSFTNGP12.phx.gbl...
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



Mar 30 '06 #5

P: n/a
to**************@uniroma1.it wrote:
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!

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:
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

Alex Clark wrote:
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


"Dustin Davis" <du**********@gmail.com> wrote in message
news:O2**************@TK2MSFTNGP12.phx.gbl...
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

Mar 31 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.