Hi All,
Some time back I needed a way to list out what USB storage drives were on the system, I used this as part of a backup program so that a user can plug in a Flash drive or USB HDD etc and the option would show in my program (without the need for openfiledialog control).
To list the drives see below code, this adds any drives to a FlowLayoutPanel as a button control. the tag is set to the drive path and the text set to the Volume Label or if not present the type of drive, there is also an AddHandler in there so we have a clickable action when the user presses said button (I have not included this as you can use for your purposes).
EnjoyCode:For Each d As System.IO.DriveInfo In My.Computer.FileSystem.Drives If d.DriveType = IO.DriveType.Removable Then Dim asd As New Button asd.Tag = d.ToString If d.VolumeLabel = "" Then asd.Text = d.DriveType.ToString Else asd.Text = d.VolumeLabel.ToString End If AddHandler asd.Button1.Click, AddressOf Me.clickme FlowLayoutPanel1.Controls.Add(asd) End If Next




Reply With Quote