Solved

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

Posted on 2007-03-28
7
175 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
Comment Utility
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
Comment Utility
sorry missed a space before the As in the For..Each
0
 
LVL 8

Assisted Solution

by:Autoeforms
Autoeforms earned 75 total points
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
oh sorry dunno that it has been posted already...
0
 

Author Comment

by:indy500fan
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now