lorena Posted November 29, 2005 Posted November 29, 2005 I have a datatable with information from files in a directory. I would like to do a reverse sort by the LastWriteDate so that the most recent file will display first. Is there a way to do this? Here is my code: Sub BindData(strSortBy As String) Dim dirInfo as New DirectoryInfo(Server.MapPath("/p1/Quality/Corr_Prev_Action_Cases/Opportunities for Improvement/Closed")) Dim arrFileInfo As Array Dim filesInfo As FileInfo Dim filesTable As New DataTable Dim drFiles As DataRow Dim dvFiles As DataView ' The table is pretty simple... could store more info, but this is ' all I display so it's all I'm storing. filesTable.Columns.Add("Name", Type.GetType("System.String")) filesTable.Columns.Add("LastWriteTime", Type.GetType("System.DateTime")) ' Get File Info arrFileInfo = dirInfo.GetFiles("*.pdf") For Each filesInfo In arrFileInfo drFiles = filesTable.NewRow() drFiles("Name") = filesInfo.Name drFiles("LastWriteTime") = filesInfo.LastWriteTime filesTable.Rows.Add(drFiles) Next filesInfo dvFiles = filesTable.DefaultView dvFiles.Sort = strSortBy dgFiles.DataSource = dvFiles dgFiles.DataBind() End Sub Quote
lorena Posted November 29, 2005 Author Posted November 29, 2005 Never mind - I figured it out dvFiles.Sort = "Date DESC" And it worked Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.