|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Selected a USB flash drive by defaultThis 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 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 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 > > 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 > > 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 > > > > tommaso.gasta***@uniroma1.it wrote:
> Thank you Dustin for the code. (I think you need an exit for, if you Acutally, I wanted the last one, since the first one will normally be > mean to catch the first one :) 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 >>> >
Problem using the shell function in a service.
How to know the Calling Object ? Update Access data How do I properly exit... System Volume Information REPOST: preventing more than one user from working on the same record Calendar with custom tooltip over days with events Using Find method on a List(of type) Breaks the Reference VB.NET error Locked Control |
|||||||||||||||||||||||