Solved

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

Posted on 2007-03-28
7
183 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

617 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