tags:

views:

118

answers:

2

Possible Duplicate:
Get List Of USB Devices

Im making a WPF app.

Im looking for a way to list all plugged in USB devices (disks!) in my comboBox.

I can list all drives using DriveInfo.GetDrives(), but is there a simple way to filter that to USB devices?

thanx

A: 

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/9f9eb8f5-297f-4acd-a9af-aafbe384fd71/

The accepted answer at that link seems to do what you're asking.

Laplace
thanx, ive been looking into that solution before, but it seemed too complicated ...
no9
+2  A: 
 foreach (DriveInfo drive in DriveInfo.GetDrives())
 {
     if (drive.DriveType == DriveType.Removable)
     {
      ..
     }
 }
Ragunathan
Be careful with this that you don't (occasionally, never with a debugger attached) get a horrible messagebox from somewhere deep in Windows asking you to insert a disk into a drive.
Will Dean
thank you. nice and simple !
no9
i have additional question.My combobox had binding to property (type List) on my viewmodel.It works fine, but if i plug in USB disk i have to reload the window in order to repopulate combobox. Is there a way that i could repopulate combobox once the USB devide is plugged in/ out ?
no9
also i shrinked the code u gave me to:return DriveInfo.GetDrives().Where(x => x.DriveType == DriveType.Removable).ToList();
no9
Use ObservableCollection in viewmodel to bind to the Combobox. Create a DispatcherTimer with some interval to check for Drives, if any new drives found add that to the observablecollection; this is will displayed in the UI.
Ragunathan