USB (removable) drives in listbox
-
I tried this:
System.IO.DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady == true & d.DriveType == "Removable") { listBox1.Items.Add(d.Name); } }
...and it did not work. I'm getting a headache. How do I accomplish what I'm trying to do? -
I tried this:
System.IO.DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady == true & d.DriveType == "Removable") { listBox1.Items.Add(d.Name); } }
...and it did not work. I'm getting a headache. How do I accomplish what I'm trying to do? -
I tried this:
System.IO.DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady == true & d.DriveType == "Removable") { listBox1.Items.Add(d.Name); } }
...and it did not work. I'm getting a headache. How do I accomplish what I'm trying to do?Try replacing
d.DriveType == "Removable"
withd.DriveType == System.IO.DriveType.Removable
.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
Try replacing
d.DriveType == "Removable"
withd.DriveType == System.IO.DriveType.Removable
.
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
Thanks a bunch, guys. The world's easiest way to list all USB drives on the system...This worked:
System.IO.DriveInfo\[\] allDrives = System.IO.DriveInfo.GetDrives(); foreach (System.IO.DriveInfo d in allDrives) { if (d.IsReady == true && d.DriveType == System.IO.DriveType.Removable) { listBox1.Items.Add(d.Name); } }
Ok. Now that we have that worked out. Let me say this: I have this code in "form1.designer.cs", which I know is incorrect. How do I get it where it belongs (in form1.cs) and have it work right? I put it in there previously, and it didn't work.
-
Thanks a bunch, guys. The world's easiest way to list all USB drives on the system...This worked:
System.IO.DriveInfo\[\] allDrives = System.IO.DriveInfo.GetDrives(); foreach (System.IO.DriveInfo d in allDrives) { if (d.IsReady == true && d.DriveType == System.IO.DriveType.Removable) { listBox1.Items.Add(d.Name); } }
Ok. Now that we have that worked out. Let me say this: I have this code in "form1.designer.cs", which I know is incorrect. How do I get it where it belongs (in form1.cs) and have it work right? I put it in there previously, and it didn't work.
simplicitylabs wrote:
I put it in there previously, and it didn't work.
It works fine for me. Was there an error message?
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
-
simplicitylabs wrote:
I put it in there previously, and it didn't work.
It works fine for me. Was there an error message?
Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.
Oh, it compiles and runs nicely. However, because I have it in form1.designer.cs, which is automatically generated by the designer, and not form1.cs, I get a warning and cannot view the form in design mode: -------The warning------- The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. ------------------------- I'm using Visual Studio 2005.
-
Oh, it compiles and runs nicely. However, because I have it in form1.designer.cs, which is automatically generated by the designer, and not form1.cs, I get a warning and cannot view the form in design mode: -------The warning------- The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. ------------------------- I'm using Visual Studio 2005.
I got it. Thank you for your help, everyone. I'm sure I'll be back with more questions soon.
-
I tried this:
System.IO.DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady == true & d.DriveType == "Removable") { listBox1.Items.Add(d.Name); } }
...and it did not work. I'm getting a headache. How do I accomplish what I'm trying to do?Have a look at: http://icsharpcode.net/OpenSource/SharpUSBLib/default.aspx