jump to navigation

File System Entries in a Data grid May 05 2004

Came across this solution while trying to interface with the local filesystem in ASP.NET (VB.NET) whatever the hell you wanna call it!

The problem was this; I’m used to binding data to a datagrid using a dataset, how do you bind data from the filesystem to the datagrid?

Here are the steps taken:

1. Create a DataTable by hand

e.g.
Dim dtblFileSystem As DataTable
dtblFileSystem = New DataTable(”file_system”)

2. Create the columns you want in the datatable

Dim dcolColumn As DataColumn

dcolColumn = New DataColumn(”inode_index”, GetType(Integer))
dtblFileSystem.Columns.Add(dcolColumn)

dcolColumn = New DataColumn(”inode_name”, GetType(String))
dtblFileSystem.Columns.Add(dcolColumn)

3. Get the contents of the directory while adding rows

Do While MyName <> “” ‘ Start the loop.

drowItem = dtblFileSystem.NewRow
drowItem(”inode_name”) = MyName
drowItem(”inode_index”) = inode_index
dtblFileSystem.Rows.Add(drowItem)

inode_index = inode_index + 1
MyName = Dir() ‘ Get next entry.
Loop

4. Now bind the datagrid to the new datatable created as a datasource

dgFileSystemList.DataSource = dtblFileSystem
dgFileSystemList.DataBind()

Comments»

no comments yet - be the first?