combobox get file lists

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My code returns the list of files in the directory I desire, but it displays
the entire path to the file and the file name. I can msgbox the desired
result (just the file name), but I believe the readonlycollection has
something to do with this...

Dim numofchars As Integer = (memberpath & "\" &
Me.EmpMemberNoTextBox.Text).ToString.Length + 1
Dim filelist As
System.Collections.ObjectModel.ReadOnlyCollection(Of String)
filelist = My.Computer.FileSystem.GetFiles(memberpath & "\"
& Me.EmpMemberNoTextBox.Text, FileIO.SearchOption.SearchTopLevelOnly)
For Each foundfile As String In filelist
Dim lengthofpath As Integer = (foundfile).Length.ToString
Dim filenamelength As Integer = lengthofpath - numofchars
Dim filename As String =
Microsoft.VisualBasic.Right(foundfile, filenamelength)
Me.ComboBxMemberFiles.Items.Add(filename.ToString)
Next

How can I display just the filename in the combo box?

Thank you!
 
Could you provide me an example of how to populate the combobox with only
filenames and NOT the entire path w/ filenames? Thank you again.
 
I found a solution to this - in case anybody else is needing to do the same:

Dim files As String() = Directory.GetFiles(memberpath &
"\" & Me.EmpMemberNoTextBox.Text)

For Each file As String In files
ComboBxGetFiles.Items.Add(Path.GetFileName(file))
Next
 
Back
Top