Solved

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

Posted on 2007-03-28
7
176 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

13 Experts available now in Live!

Get 1:1 Help Now