I have a page which lists all the files in a particular folder (all PDFs), using a data-table and gridview.
I'm currently sorting this table by the filename (by using a dataview), which isn't that helpful, and I want the gridview of files sorted by the file created or file modified date (as recorded in Windows).
If that's not possible, a second option would be to extract the date from the file name string (no problem doing that), and sort the dataview/datatable or gridview based on that. Example Filename: DailySalesReport-1-15-2010. My only hangup with this is how do I sort on date, when it's a string value? Convert to date? How would I sort the whole dataset based on this converted value?
Thanks for any ideas!
Protected Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As New DataTable()
dt.Columns.Add("Daily Reports", Type.[GetType]("System.String"))
For Each name As [String] In System.IO.Directory.GetFiles(Server.MapPath("~\reports\pdf\")) '"
dt.Rows.Add(New Object() {name})
Next
Dim dv As DataView = dt.DefaultView
dv.Sort = dt.Columns(0).ToString + " " + "desc"
dt = dv.ToTable
Me.gvDaily.DataSource = dt
Me.gvDaily.DataBind()
End If
End Sub
Protected Sub gvDaily_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim hl As New HyperLink()
hl.NavigateUrl = "~\reports\pdfs\" + e.Row.Cells(0).Text '"
hl.Text = "Daily Report"
e.Row.Cells(0).Text = ""
e.Row.Cells(0).Controls.Add(hl)
End If
End Sub
<asp:GridView ID="gvDaily" runat="server" Height="80px" Width = "180px" CssClass="tableText"
OnRowDataBound="gvDaily_RowDataBound">
<RowStyle HorizontalAlign="center" />
</asp:GridView>