How to list multiple file types with this code vb.net aspx

I found this code from the asp.net guys and would like to list the files in a folder with multiple file types, for example I would like to list .iso, .exe, .zip and not .aspx files. Can anyone help with this. I have been searching around but I am not a good enough coder to figure this out right now.

### Code Below


Sub Page_Load(sender as Object, e as EventArgs)
    Dim dirInfo as New DirectoryInfo(Server.MapPath(""))
   
    articleList.DataSource = dirInfo.GetFiles("*.iso")
    articleList.DataBind()
  End Sub

</script>


<asp:DataGrid runat="server" id="articleList" Font-Name="Verdana"
      AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
      HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
      HeaderStyle-Font-Size="8pt" HeaderStyle-Font-Bold="True">
  <Columns>
    <asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" HeaderText="File Name" />
    <asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
    <asp:BoundColumn DataField="Length" HeaderText="File Size" ItemStyle-HorizontalAlign="Right" DataFormatString="{0:#,### bytes}" />
  </Columns>
</asp:DataGrid>  
ngranickAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SriVaddadiCommented:
Dim dir As New DirectoryInfo(Server.MapPath("~"))
        Dim isoFiles() As FileInfo
        Dim zipFiles() As FileInfo
        Dim exeFiles() As FileInfo
        Dim aspxFiles() As FileInfo
        Dim allFiles() As FileInfo

        isoFiles = dir.GetFiles("*.iso")
        zipFiles = dir.GetFiles("*.zip")
        exeFiles = dir.GetFiles("*.exe")
        aspxFiles = dir.GetFiles("*.aspx")
        ReDim allFiles(isoFiles.Length + zipFiles.Length + exeFiles.Length + aspxFiles.Length)
        isoFiles.CopyTo(allFiles, 0)
        zipFiles.CopyTo(allFiles, isoFiles.Length)
        exeFiles.CopyTo(allFiles, isoFiles.Length + zipFiles.Length)
        aspxFiles.CopyTo(allFiles, isoFiles.Length + zipFiles.Length + exeFiles.Length)

articleList.DataSource = allfiles
articleList.DataBind()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ngranickAuthor Commented:
Fantastic. worked like a champ. Thanks for the superfast response!
0
ngranickAuthor Commented:
This code works great. Only issue I have found is that when there are no files in the folder of the files types specified the aspx page errors out and this is what it gives back.

Any idea how to not error out this hard and show the web page even when there is no files in the folder on the web server?


Server Error in '/' Application.
A field or property with the name 'Name' was not found on the selected data source.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the name 'Name' was not found on the selected data source.
0
SriVaddadiCommented:
Try this

        Dim dir As New DirectoryInfo(Server.MapPath("~"))
        Dim isoFiles() As FileInfo
        Dim zipFiles() As FileInfo
        Dim exeFiles() As FileInfo
        Dim aspxFiles() As FileInfo
        Dim allFiles(0) As FileInfo

        isoFiles = dir.GetFiles("*.iso")
        zipFiles = dir.GetFiles("*.zip")
        exeFiles = dir.GetFiles("*.exe")
        aspxFiles = dir.GetFiles("*.aspx")
        ReDim allFiles(isoFiles.Length + zipFiles.Length + exeFiles.Length + aspxFiles.Length)
        isoFiles.CopyTo(allFiles, 0)
        zipFiles.CopyTo(allFiles, isoFiles.Length)
        exeFiles.CopyTo(allFiles, isoFiles.Length + zipFiles.Length)
        aspxFiles.CopyTo(allFiles, isoFiles.Length + zipFiles.Length + exeFiles.Length)

        If (allFiles.Length > 1) Then
            articleList.DataSource = allFiles
            articleList.DataBind()
        End If
0
ngranickAuthor Commented:
Perfection!! Thanks again Sri!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.