如何通过字母数字对下面此目录中的文件进行排序? 文件示例:12325_2011.jpg
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim di As New IO.DirectoryInfo(ImagePath)
Dim imageArray As IO.FileInfo() = di.GetFiles()
Dim image As IO.FileInfo
'list the names of all images in the specified directory
For Each image In imageArray
CheckBoxList1.Items.Add(image.Name)
Next
End If
End Sub
答案 0 :(得分:4)
只需修改现有的For Each循环:
For Each image In imageArray.OrderBy(Function(i) i.Name)
CheckBoxList1.Items.Add(image.Name)
Next
答案 1 :(得分:0)
您可以使用排序列表类而不是图像数组:
http://msdn.microsoft.com/en-us/library/system.collections.sortedlist.aspx
e.g。
For each Item in di.GetFiles
'Add image url to sorted list
Next
For Each Item in SortedList
'Add to checkbox list
Next