100% FREE Monitoring
Website Checks every 10 minutes. Email alerts with false alert prevention technology.
Get Started Now!
How Does it Work?

FREE SEO Link Exchange
To increase your page rank and do it all for free, check out LinkMarket.com.



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 Bind Directory List to DataGrid

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