- Sub binddata()
- Dim strBaseFolder As String = Server.MapPath("\bulletins")
- Dim oDT As New DataTable
- 'create column 1
- Dim fileName As DataColumn = New DataColumn("fileName", System.Type.GetType("System.String"))
- oDT.Columns.Add(fileName)
- 'create column 2
- Dim fullPath As DataColumn = New DataColumn("fullPath", System.Type.GetType("System.String"))
- oDT.Columns.Add(fullPath)
- 'create column 3
- Dim relPath As DataColumn = New DataColumn("relPath", System.Type.GetType("System.String"))
- oDT.Columns.Add(relPath)
- For Each s As String In Directory.GetFiles(strBaseFolder)
- 'create the rows
- Dim oRow As DataRow
- oRow = oDT.NewRow
- oRow("fileName") = Path.GetFileName(s)
- oRow("fullPath") = s
- oRow("relPath") = "~/bulletins/" & Path.GetFileName(s)
- oDT.Rows.Add(oRow)
- Next s
- Dim oDV As DataView = oDT.DefaultView
- oDV.Sort = "fileName desc"
- Me.Grid1.DataSource = oDV
- Me.Grid1.DataBind()
- End Sub
Populate a DataTable with the files in a folder, sort using a DataView
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment