Groups | Blog | Home
all groups > dotnet general > may 2006 >

dotnet general : combobox get file lists


mafandon
5/12/2006 4:02:01 PM
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?

Tedmond
5/12/2006 6:27:01 PM
Uses FileInfo class to help you to get filename from a full path.

Tedmond

[quoted text, click to view]
Cor Ligthert [MVP]
5/13/2006 12:00:00 AM
Mafandon,

I use the Path Class to get parts of paths.

http://msdn2.microsoft.com/en-us/library/system.io.path.aspx

I hope this helps,

Cor

"mafandon" <mafandon@discussions.microsoft.com> schreef in bericht
news:DF5E2EC8-C83F-4B7C-9556-A58495861104@microsoft.com...
[quoted text, click to view]

mafandon
5/15/2006 5:57:02 PM
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.

[quoted text, click to view]
mafandon
5/17/2006 9:19:02 AM
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


[quoted text, click to view]
AddThis Social Bookmark Button