Thread: GetFiles() Help
View Single Post
  #3 (permalink)  
Old April 5th, 2008, 01:06 PM
adamcherochak adamcherochak is offline
Authorized User
 
Join Date: Sep 2007
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

As usual, your code is awesome! I am truly impressed with the LINQ example! However, I'm trying to pass multiple patterns to GetFiles().

searchPattern returns all file types which is stored in an array of FileInfo(). I then use two separate arrays to loop through everything then store the files with the desired extensions which becomes my DataSource.

I've modified my code to match your example, but I am at a complete loss inside the nested IF Statement. I cannot use .Add in there.

Code:
Dim basePath As String = Server.MapPath("~/UploadFolder/")
Dim searchPattern As String = "*.*"

Dim dirInfo As New DirectoryInfo(basePath)
Dim fileArray As FileInfo() = dirInfo.GetFiles(searchPattern)

Dim specificFile As FileInfo
Dim secondArray As FileInfo

     For Each specificFile In fileArray
          If specificFile.Extension = ".htm" Or specificFile.Extension = ".ppt" Then
          'collect files with desired extensions
          secondArray.Add(specificFile)
          End If
     Next specificFile
dgArticleList.DataSource = secondArray
dgArticleList.DataBind()