This article adds the files in a directory (with wildcards) into a datatable, then to a dataset.With slight modifications to this function you can return the file list as a dataset, datatable or string array.
Private Sub TabArchivesEvents()
Dim archivePath As String
Dim dirInfo As DirectoryInfo
archivePath = System.Configuration.ConfigurationSettings.AppSettings("ExecutiveAnalysisArchivesFolder") & Me.DLR_ID & "\"
If Directory.Exists(archivePath) Then
dirInfo = New DirectoryInfo(archivePath)
Dim dt As New DataTable
Dim dc As DataColumn
Dim dr As DataRow
dc = New DataColumn("Name", System.Type.GetType("System.String"))
dt.Columns.Add(dc)
dc = New DataColumn("Size", System.Type.GetType("System.Double"))
dt.Columns.Add(dc)
For Each fi As FileInfo In dirInfo.GetFiles("*.*")
dr = dt.NewRow
dr.Item("Name") = fi.Name
dr.Item("Size") = Round(fi.Length / 1024, 2) 'Now in KB
dt.Rows.Add(dr)
Next
dt.DefaultView.Sort = "Name DESC"
grdFiles.DataSource = dt
grdFiles.DataBind()
End If
lblFileCount.Text = "Showing " & grdFiles.Items.Count & " of " & dirInfo.GetFileSystemInfos("*.*").Length & " Reports"
End Sub
Public Shared Function GetHTMLStack() As DataSet
Dim dir As Directory
Dim Files As String()
Dim file As String
Dim dtFiles As New DataTable
Dim dtCol As DataColumn
Dim dtRow As DataRow
dtCol = New DataColumn
dtCol.DataType = System.Type.GetType("System.String")
dtCol.ColumnName = "htmlFile"
dtFiles.Columns.Add(dtCol)
Files = dir.GetFiles(Generator.htmlStackPath, "*.html")
For Each file In Files
dtRow = dtFiles.NewRow
dtRow.Item("htmlFile") = Generator.htmlStackPath & file
dtFiles.Rows.Add(dtRow)
Next
Dim ds As New DataSet
ds.Tables.Add(dtFiles)
Return ds
End Function