<p>How can I discover any USB storage devices and/or CD/DVD writers available at a given time (using C# .Net2.0).</p>

<p>I would like to present users with a choice of devices onto which a file can be stored for physically removal - i.e. not the hard drive.</p>

[{'answer_id': 51656, 'author': 'sven', 'author_id': 46, 'author_profile': 'https://Stackoverflow.com/users/46', 'pm_score': 1, 'selected': False, 'text': '<p>this is VB.NET code to check for any removable drives or CDRom drives attached to the computer:</p>\n\n<pre><code>Me.lstDrives.Items.Clear()\nFor Each item As DriveInfo In My.Computer.FileSystem.Drives\n    If item.DriveType = DriveType.Removable Or item.DriveType = DriveType.CDRom Then\n        Me.lstDrives.Items.Add(item.Name)\n    End If\nNext\n</code></pre>\n\n<p>it won\'t be that hard to modify this code into a c# equivalent, and more <em>driveType</em>\'s are available.<br>\n<a href="http://msdn.microsoft.com/en-us/library/system.io.drivetype.aspx" rel="nofollow noreferrer">From MSDN:</a></p>\n\n<ul>\n<li><strong>Unknown:</strong>     The type of drive is unknown.  </li>\n<li><strong>NoRootDirectory:</strong>    The drive does not have a root directory.</li>\n<li><strong>Removable:</strong>  The drive is a removable storage device, such as a floppy disk drive or a USB flash drive.</li>\n<li><strong>Fixed:</strong>  The drive is a fixed disk.</li>\n<li><strong>Network:</strong>    The drive is a network drive.</li>\n<li><strong>CDRom:</strong>  The drive is an optical disc device, such as a CD or DVD-ROM.   </li>\n<li><strong>Ram:</strong>    The drive is a RAM disk.</li>\n</ul>\n'}, {'answer_id': 51672, 'author': 'Mark Ingram', 'author_id': 986, 'author_profile': 'https://Stackoverflow.com/users/986', 'pm_score': 4, 'selected': True, 'text': '<pre><code>using System.IO;\n\nDriveInfo[] allDrives = DriveInfo.GetDrives();\nforeach (DriveInfo d in allDrives)\n{\n  if (d.IsReady &amp;&amp; d.DriveType == DriveType.Removable)\n  {\n    // This is the drive you want...\n  }\n}\n</code></pre>\n\n<p>The DriveInfo class documentation is here:</p>\n\n<p><a href="http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx</a></p>\n'}, {'answer_id': 51678, 'author': 'Hath', 'author_id': 5186, 'author_profile': 'https://Stackoverflow.com/users/5186', 'pm_score': 1, 'selected': False, 'text': '<p>in c# you can get the same by using the System.IO.DriveInfo class</p>\n\n<pre><code>using System.IO;\n\npublic static class GetDrives\n{\n    public static IEnumerable&lt;DriveInfo&gt; GetCDDVDAndRemovableDevices()\n    {\n        return DriveInfo.GetDrives().\n            Where(d =&gt; d.DriveType == DriveType.Removable\n            &amp;&amp; d.DriveType == DriveType.CDRom);\n    }\n\n}\n</code></pre>\n'}, {'answer_id': 12752540, 'author': 'Searush', 'author_id': 1587402, 'author_profile': 'https://Stackoverflow.com/users/1587402', 'pm_score': 0, 'selected': False, 'text': "<p>This is a complete module for VB.NET : <br>\nImports System.IO <br>\nModule GetDriveNamesByType <br>\n    Function GetDriveNames(Optional ByVal DType As DriveType = DriveType.Removable) As ListBox <br>\n        For Each DN As System.IO.DriveInfo In My.Computer.FileSystem.Drives <br>\n            If DN.DriveType = DType Then <br>\n                GetDriveNames.Items.Add(DN.Name) <br>\n            End If <br>\n        Next <br>\n    End Function <br>\nEnd Module <br></p>\n\n<pre><code>'Drive Types &lt;br&gt;\n'Unknown: The type of drive is unknown. &lt;br&gt;\n'NoRootDirectory: The drive does not have a root directory. &lt;br&gt;\n'Removable: The drive is a removable storage device, such as a floppy disk drive or a USB flash drive. &lt;br&gt;\n'Fixed: The drive is a fixed disk. &lt;br&gt;\n'Network: The drive is a network drive. &lt;br&gt;\n'CDRom: The drive is an optical disc device, such as a CD or DVD-ROM. &lt;br&gt;\n'Ram: The drive is a RAM disk. &lt;br&gt;\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/51645', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5019/']