How To load Availale Drives In Combobox In VB.NET

I saw on some forums, many people asking how to get the available drives in a combobox or whatever in VB.NET, here is the code that get's the available drives in a combobox, you can change combobox to listbox and etc.
Imports Microsoft.Win32
Imports System.IO
Public Class form1

    'Author : Mohamed Shimran
    'Blog : http://www.ultimateprogrammingtutorials.blogspot.com

    Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        For Each drive In Environment.GetLogicalDrives
            Dim Driver As DriveInfo = New DriveInfo(drive)

            If Driver.DriveType = DriveType.Removable Or Driver.DriveType = DriveType.Fixed Then

                ComboBox1.Items.Add(drive)
            End If
        Next
    End Sub
End Class

working

2 comments

how to load every all files with extension ".png" for specific folder

Reply

Hi,

Here you go :

Try
Dim di As New DirectoryInfo("directory goes here")
Dim fiArr As FileInfo() = di.GetFiles()
Dim fri As FileInfo
For Each fri In fiArr
If fri.Extension = ".png" Then
Dim s As String
s = fri.Name
lstImages.Items.Add(s.Substring(0, s.Length - 4))
End If
Next fri
Catch ex As Exception

End Try

Reply

Post a Comment

Note: Only a member of this blog may post a comment.