Solved

Need syntax help to add filenames, located in a specific directory, to a combobox

Posted on 2007-03-28
7
177 Views
Last Modified: 2010-04-23
I want to be able to look at all the files in a directory (C:\SSISExports), and add them to a combobox.  

I assume it is something like:

    Dim strSSISPackage As [String]
    Private Sub cmbSelectIndividualSSISPackage_CLick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbSelectIndividualSSISPackage.SelectedIndexChanged
        For Each strSSISPackage In ???.???
            cmbSelectIndividualSSISPackage.Items.Add(strSSISPackage)
        Next strSSISPackage
    End Sub

I also need the appropriate Imports statement if necessary.

Thanks in advance!

Regards,
Eric
0
Comment
Question by:indy500fan
7 Comments
 
LVL 11

Accepted Solution

by:
Babycorn-Starfish earned 250 total points
ID: 18812832
Hi,

add
imports System.IO

then use the following code in your event handler


        For Each strSSISPackageAs String In Directory.GetFiles("C:\SSISExports")
                    cmbSelectIndividualSSISPackage.Items.Add(strSSISPackage)
        Next

i would also though to be on the safe side check whether that path exists, just in case it doesn't on one occassion, use

If (Directory.Exists("C:\SSISExports")) Then
            For Each filename As String In Directory.GetFiles("C:\SSISExports")
                Me.ComboBox1.Items.Add(filename)
            Next
        Else
            MessageBox.Show("Some kind of error notofication or recovery")
End If

hope this helps
0
 
LVL 11

Expert Comment

by:Babycorn-Starfish
ID: 18812833
sorry missed a space before the As in the For..Each
0
 
LVL 8

Assisted Solution

by:Autoeforms
Autoeforms earned 75 total points
ID: 18812836
code below should help you

good luck
greg


            sFileList = System.IO.Directory.GetFiles(sFilePath, "*.txt")
            If sFileList.Length <= 0 Then Return 0
             For Each sFileName In sFileList
' add to combo box
            Next
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
ID: 18812853
If you don't the path of the file in there then you can do:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim di As New System.IO.DirectoryInfo("C:\SSISExports")
        If di.Exists Then
            For Each fi As System.IO.FileInfo In di.GetFiles
                cmbSelectIndividualSSISPackage.Items.Add(fi.Name)
            Next
        End If
    End Sub

End Class
0
 
LVL 2

Assisted Solution

by:TheUnkind
TheUnkind earned 75 total points
ID: 18812868
Hi, try this one:

the import ---> Imports System.IO

the code:

        ComboBox1.Items.Clear()
        ComboBox1.Items.AddRange(Directory.GetFiles("C:\SSISExports", "*.*"))

though even the hidden files can be gather with this kind of method... you'll have to use the for each ... and File.GetAttributes(files) statement for this...

like:

for each files as string in Directory.Getfiles("C:\SSISExports", "*.*")
 if File.GetAttributes(files) <> FileAttributes.Hidden then ComboBox1.Items.Add(files)
next




0
 
LVL 2

Expert Comment

by:TheUnkind
ID: 18812872
oh sorry dunno that it has been posted already...
0
 

Author Comment

by:indy500fan
ID: 18815108
Thanks Everybody!

Here's why I divied up the points.  BCS gave me a solution and they were first, so they go the most points; however, I learned something from each of you.

I also gave IdleMind a bit more because I was going to as khow to just get the file name, and they went ahead and put that in there.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question