How to list ALL filtered filenames (with path) from Folder Browser control?

K

kimiraikkonen

Hello,
I have a listbox and folder browser control. I need to display
all .mp3 files' pathes into listbox.

It was Ok with openfiledialog but how can list all .mp3 extension-
having files into my listbox using folder browser control.

A sample code would be great.


Thanks...
 
C

Cor Ligthert[MVP]

Kimiraikkonen,

The folder browser is not to list files, it list the directories. The normal
one for this is the OpenFileDialog.

Cor
 
K

kimiraikkonen

Kimiraikkonen,

The folder browser is not to list files, it list the directories. The normal
one for this is the OpenFileDialog.

Cor

"kimiraikkonen" <[email protected]> schreef in bericht






- Show quoted text -

Hello,
I want to see all .mp3 filenames in a listbox which are in a
directory, i mean i want to add dirrectory into a listbox to see their
filenames.
 
R

rowe_newsgroups

Why you want a folderbrowser while the openfiledialog with a filter does
that direct?

I cannot give you a link, MSDN seems to be unavailable.

However you can search for that later.

http://msdn2.microsoft.com/en-us/default.aspx

Cor

Cor, I believe the OP is not trying to build a file picker, but is
trying to find the files for an MP3 player based on other posts I've
responded to by the OP.

To the OP:

Here is some code that will search a path and subpaths for any .mp3
files and load them into the listbox I showed you in an earlier post.
Be warned, this is very slow and probably should be set up to run
asynchronously, and will die if it hits any directories it does not
have permission to access. These are two issues you need to solve on
your own.

To use this code create a new windows form application and add a
listbox to Form1. Then replace the code-behind with the following
code:

//////////////////////
Imports System.IO

Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
LoadFiles()
End Sub

Private Sub LoadFiles()
Dim files As String() = Directory.GetFiles("C:\", "*.mp3",
SearchOption.AllDirectories)
For Each file As String In files
Me.ListBox1.Items.Add(New
FileInformation(Path.GetFileName(file), file))
Next
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
Try
Dim item As FileInformation =
DirectCast(Me.ListBox1.SelectedItem, FileInformation)
MsgBox(String.Format("The path for item '{0}' is '{1}'",
item.FileName, item.FilePath), MsgBoxStyle.OkOnly, "File Information")
Catch ex As InvalidCastException
MsgBox("The selected file was not found.")
'// Remove the item to prevent further troubles
Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItem)
End Try
End Sub
End Class

Public Class FileInformation

Public Sub New()

End Sub

Public Sub New(ByVal fileName As String, ByVal filePath As String)
Me.FileName = fileName
Me.FilePath = filePath
End Sub

Public Property FileName() As String
Get
Return _FileName
End Get
Set(ByVal value As String)
_FileName = value
End Set
End Property
Private _FileName As String = String.Empty

Public Property FilePath() As String
Get
Return _FilePath
End Get
Set(ByVal value As String)
_FilePath = value
End Set
End Property
Private _FilePath As String = String.Empty

Public Overrides Function ToString() As String
Return FileName
End Function

End Class
//////////////////////

Thanks,

Seth Rowe
 
A

Armin Zingler

kimiraikkonen said:
If so, would you send me the whole code which allows me to retrieve
all the files' names into text boxes from a entire folder.

Use System.IO.Directory.GetFiles or System.IO.DirectoryInfo.GetFiles. Press
F1 to get examples.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top