I have an Intranet page that looks at a folder of files and lists them out.  It uses io.directoryinfo.getfiles to get the list of files but there wasn’t anyway to control the sorting.  By default it was sorting ascending but i wanted it reversed.  Here’s what I had at first:

Dim di As New IO.DirectoryInfo(Server.MapPath(“FolderofFiles”))
Dim aryFi As IO.FileInfo() = di.GetFiles(“*.pdf”)
Dim fi As IO.FileInfo
For Each fi In aryFi
..blah blah loop
Next

I tried to add Array.Sort(aryFi) but that resulted in an error:
“At least one object must implement IComparable.”

So after some internet searching I came up with the following based on a post on stackoverflow.com

First you have to create an IComparer class:

Private Class FileNameComparer
Implements System.Collections.IComparer
Public Function Compare(ByVal info1 As Object, ByVal info2 As Object) As Integer Implements System.Collections.IComparer.Compare
Dim FileInfo1 As System.IO.FileInfo = DirectCast(info1, System.IO.FileInfo)
Dim FileInfo2 As System.IO.FileInfo = DirectCast(info2, System.IO.FileInfo)
Dim Filename1 As String = FileInfo1.FullName
Dim Filename2 As String = FileInfo2.FullName
If Filename1 > Filename2 Then Return -1
If Filename1 < Filename2 Then Return 1
Return 0
End Function
End Class

Then use the comparer to sort:

Dim di As New IO.DirectoryInfo(Server.MapPath(“Folderoffiles”))
Dim aryFi As IO.FileInfo() = di.GetFiles(“*.pdf”)
Dim comparer As IComparer = New FileNameComparer()
Array.Sort(aryFi, comparer)
Dim fi As IO.FileInfo
For Each fi In aryFi
..blah blah loop
Next

The comparer I tweaked sorts the files by their filename in a descending order.  You can reverse the Return -1 and Return 1 to get them into ascending order.
Also, if you would like to sort the files by creation date you could use this comparer:

Private Class DateComparer
Implements System.Collections.IComparer
Public Function Compare(ByVal info1 As Object, ByVal info2 As Object) As Integer Implements System.Collections.IComparer.Compare
Dim FileInfo1 As System.IO.FileInfo = DirectCast(info1, System.IO.FileInfo)
Dim FileInfo2 As System.IO.FileInfo = DirectCast(info2, System.IO.FileInfo)
Dim Date1 As DateTime = FileInfo1.CreationTime
Dim Date2 As DateTime = FileInfo2.CreationTime
If Date1 > Date2 Then Return 1
If Date1 < Date2 Then Return -1
Return 0
End Function
End Class

Then you’d change:

Dim comparer As IComparer = New FileNameComparer()
to
Dim comparer As IComparer = New DateComparer()