Drop Down List Item Order

I've got a drop down list with dynamically generated content. It pulls the names of a bunch of report files. The problem is that the files are listed oldest to newest and I would like the newest files to be at the top of the list as there can potentially be hundreds of files in the list.

Here are a couple example file names:
SmSqlRpt_Backup [SQLServer1]_04-04-2011_13.31.24.txt
SmSqlRpt_Backup [SQLServer1]_04-04-2011_14.31.13.txt

With the code below they are listed in the drop down box in this order. What I want to do is reverse that order and have the newest backup report first in the list.
Dim Table1 As DataTable
        Table1 = New DataTable("Report List")

        Dim smsqlFiles As DataColumn = New DataColumn("Files")
        smsqlFiles.DataType = System.Type.GetType("System.String")
        Table1.Columns.Add(smsqlFiles)

        Dim reportName As DataColumn = New DataColumn("Name")
        reportName.DataType = System.Type.GetType("System.String")
        Table1.Columns.Add(reportName)

        Dim datPath As String = txtPath.Text & "\SMSQLInfo\"
        Dim datFile As String() = IO.Directory.GetFiles(txtPath.Text & "\SMSQLInfo\")
        Dim file = From p In datFile Where p.Contains("SmSqlRpt") Select p
        Dim logName = From q In file Where q.Contains("SmSqlRpt") Select q.Replace(datPath, String.Empty).Trim

        For Each log In file
            'txtOut.Text &= log
            'txtOut.Text &= vbCrLf

            Dim Row1 As DataRow
            Try
                Row1 = Table1.NewRow()
                Row1.Item(smsqlFiles) = log
                Row1.Item(reportName) = IO.Path.GetFileName(log)
                Table1.Rows.Add(Row1)
            Catch ex As Exception

            End Try

        Next

        drpSnapManagerReports.DataTextField = Table1.Columns(1).ToString
        drpSnapManagerReports.DataValueField = Table1.Columns(0).ToString
        drpSnapManagerReports.DataSource = Table1
        drpSnapManagerReports.DataBind()

Open in new window

LVL 1
newimagentAsked:
Who is Participating?
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.

CodeCruiserCommented:
Are all the file names always in that format? If yes then you can do some string magic

Dim str as string = filename.substring(filename.length - 23, 23)
Dim words as string() = str.split("_")

now you have words(0) = date and words(1) = time. Replace - with / etc and put this info in another date column in your datatable and sort on that column.
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
käµfm³d 👽Commented:
I'd say throw an Order By on your query:

Dim file = From p In datFile _
           Let dVal = System.Text.RegularExpressions.Match(p, "\d\d-\d\d-\d\d\d\d").Value _
           Where p.Contains("SmSqlRpt") _
           Order By DateTime.Parse(dVal) Descending _
           Select p

Open in new window

0
käµfm³d 👽Commented:
P.S.

You don't *need* to use regex to extract the date; you can use something like CodeCruiser's suggestion.
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.