Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...