2

I am making a program in C# and I got a lot of tips from this site. But now I am facing a problem I can't solve.

I want the program to download a file from the internet to an USB device. This USB device must be selected in a Combobox. The code I used for this is:

var drives = from drive in DriveInfo.GetDrives() //search removable drives
             where drive.DriveType == DriveType.Removable
             select drive;

dropdowndrive.DataSource = drives.ToList(); //add removable drives to combobox

It works but only when I insert the USB drive before booting the program. How can I show a removable device which has been inserted after booting the program?

Jeff B
  • 8,572
  • 17
  • 61
  • 140
  • 1
    Your code is in the Form Load event? You can have a 'refresh drives' button that executes your code in the onclick event... – rene Nov 04 '12 at 13:17
  • 1
    Or maybe have the list refreshed on some event on the combobox. Maybe the [GotFocus Event](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus.aspx) – Johan Larsson Nov 04 '12 at 13:19
  • 1
    Maybe helpfull: http://www.codeproject.com/Articles/63878/Enumerate-and-Auto-Detect-USB-Drives – rene Nov 04 '12 at 13:21
  • Take the code from the accepted answer to [this question](http://stackoverflow.com/questions/271238/how-do-i-detect-when-a-removable-disk-is-inserted-using-c) and in the `USBInserted` and `USBRemoved` methods refresh the combobox. – Shadow The GPT Wizard Nov 04 '12 at 13:22

0 Answers0