954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

List all .text file in Combobox

Hi Alls,

Really need your help.
I'm trying to list all text file in Application Startup path folder in combobox but cannot...can anyone help?.....In Application Startup Path folder i got more than 3 .txt file. So i want to list out in combobox...please help me..thank you

kerek2
Junior Poster
118 posts since Sep 2007
Reputation Points: 20
Solved Threads: 0
 

here try this:

Imports System.IO
Imports System.IO.Path
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strPath As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\"

        Dim dirInfo As New IO.DirectoryInfo(strPath)

        For Each file As FileInfo In dirInfo.GetFiles("*.txt", SearchOption.TopDirectoryOnly)
            ComboBox1.Items.Add(file.Name)
        Next

    End Sub
End Class
Attachments temp.PNG 10.96KB
sandeepparekh9
Posting Whiz
367 posts since Dec 2010
Reputation Points: 123
Solved Threads: 71
 

This might help also. Just change the ListBox to a ComboBox.

Dim myCoolFolder As String = "C:\!vbTemp\" '// your folder.

        For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
                                                    (myCoolFolder, FileIO.SearchOption.SearchTopLevelOnly, "*.*")
            ListBox1.Items.Add(IO.Path.GetFileName(myCoolFile)) '// add file name with extension.
        Next

        '// to search subfolders, change "SearchTopLevelOnly" to "SearchAllSubDirectories".
        '// to only get a certain file type, change "*.*" to your file type.
        '//-- example for .txt files: "*.txt"
codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

tq all...ur are awesome.....

kerek2
Junior Poster
118 posts since Sep 2007
Reputation Points: 20
Solved Threads: 0
 

Since you cannot receive private messages, I'll post here and remind you to not forget to mark the thread solved if Solved. And of course, glad I could help. :)

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: