List the contents of a Directory in a .NET DataGrid
It is pretty straight forward to bind a list of files to a datagrid using the GetFiles() function.
.ASPX Code
Code Sample
VB Code Behind
Imports System
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
'Path for files to be listed
Dim dirInfo As New DirectoryInfo(Server.MapPath("KB\"))
'Get all files with extension *.aspx
articleList.DataSource = dirInfo.GetFiles("*.aspx")
'Bind to Grid
articleList.DataBind()
Catch excpt As System.Exception
Response.Write("ERROR: Directory Search " & (excpt.Message))
End Try
End Sub
End Class
'FILE Properties: http://msdn.microsoft.com/en-us/library/as4xcs58(VS.80).aspx