David, I did it at last. This is the code:
Sub Page_Load(.....)
Dim i As Integer
Dim aList As ArrayList
Dim fsi As FileSystemInfo
Dim dInfo As DirectoryInfo
Dim strListItemValue As String
aList = New ArrayList
dInfo = New DirectoryInfo(Server.MapPath("Folder1"))
For Each fsi In dInfo.GetFileSystemInfos
If ((fsi.Attributes And FileAttributes.Directory) = 16) Then
'precede all directory names with 0
'so that they get listed before the files
aList.Add("0" & fsi.Name & "<DIR>")
Else
'precede all file names with 1 so that
'that they get listed after the directories
aList.Add("1" & fsi.Name & "<FILE>")
End If
Next
aList.Sort()
For i = 0 To aList.Count - 1
If (InStr(aList(i), "<DIR>") > 0) Then
'this item is a directory
strListItemValue = Left(aList(i), Len(aList(i)) - 5)
strListItemValue = Mid(strListItemValue, 2,
Len(strListItemValue)) & "+D"
Else
'this item is a file
strListItemValue = Left(aList(i), Len(aList(i)) - 6)
strListItemValue = Mid(strListItemValue, 2,
Len(strListItemValue)) & "+F"
End If
'get rid of the 0s & 1s preceding all the
'ListItems to display the file/directory name
lstFD.Items.Add(New ListItem(Mid(aList(i), 2, Len(aList(i))),
strListItemValue))
Next
End Sub