Home All Groups Group Topic Archive Search About

Selected a USB flash drive by default

Author
29 Mar 2006 11:00 PM
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

Author
29 Mar 2006 11:27 PM
Alex Clark
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




Show quoteHide quote
"Dustin Davis" <dustin.da***@gmail.com> wrote in message
news:O2UmZS4UGHA.5808@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
Author
30 Mar 2006 6:26 PM
Dustin Davis
Wow - Awesome, thanks for the info!

Alex Clark wrote:
Show quoteHide quote
> 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" <dustin.da***@gmail.com> wrote in message
> news:O2UmZS4UGHA.5808@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
>
>
Author
30 Mar 2006 8:22 PM
Dustin Davis
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:
Show quoteHide quote
> 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" <dustin.da***@gmail.com> wrote in message
> news:O2UmZS4UGHA.5808@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
>
>
Author
30 Mar 2006 11:29 PM
tommaso.gastaldi
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:

Show quoteHide quote
> 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" <dustin.da***@gmail.com> wrote in message
> > news:O2UmZS4UGHA.5808@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
> >
> >
Author
31 Mar 2006 6:12 PM
Dustin Davis
tommaso.gasta***@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!

Show quoteHide quote
>
> 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" <dustin.da***@gmail.com> wrote in message
>>> news:O2UmZS4UGHA.5808@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
>>>
>