Solved

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

Posted on 2007-03-28
7
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 86

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

752 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