How do you bind a DirectoryInfo[] to a GridView

S

Steve Kershaw

Hi,

I need a way to bind a DirectoryInfo[] array to a GridView without any
errors.

The code I'm using to create the DirectoryInfo[] array is:

// Define the current directory
DirectoryInfo dir = new DirectoryInfo("C:\\Temp\\");

// Get the Directory info array
DirectoryInfo[] dirs = dir.GetDirectories();

This works fine, but everytime I try to bind it to the GridView I get
an error (something about LastWriteTime not found).

Can anybody help Please!!!

Thanks
Steve
 
G

Guest

Hi,

I need a way to bind a DirectoryInfo[] array to a GridView without any
errors.

The code I'm using to create the DirectoryInfo[] array is:

// Define the current directory
DirectoryInfo dir = new DirectoryInfo("C:\\Temp\\");

// Get the Directory info array
DirectoryInfo[] dirs = dir.GetDirectories();

This works fine, but everytime I try to bind it to the GridView I get
an error (something about LastWriteTime not found).

Can anybody help Please!!!

Thanks
Steve

Do you need that column?

<asp:GridView
AutoGenerateColumns="False"
....<Columns>
<asp:BoundField DataField="Name"
HeaderText="Dir Name" />
</Columns>
</asp:GridView>
 
S

Steve Kershaw

I need a way to bind a DirectoryInfo[] array to a GridView without any
errors.
The code I'm using to create the DirectoryInfo[] array is:
// Define the current directory
DirectoryInfo dir = new DirectoryInfo("C:\\Temp\\");
// Get the Directory info array
DirectoryInfo[] dirs = dir.GetDirectories();
This works fine, but everytime I try to bind it to the GridView I get
an error (something about LastWriteTime not found).
Can anybody help Please!!!
Thanks
Steve

Do you need that column?

<asp:GridView
AutoGenerateColumns="False"
...

<Columns>
<asp:BoundField DataField="Name"
HeaderText="Dir Name" />
</Columns>
</asp:GridView>- Hide quoted text -

- Show quoted text -

Thanks for writing. I have the AutoGenerateColumns="false" set
already.
Any other ideas?
 
D

David R. Longnecker

Steve-

Here's the code I came up with. Be sure you have access to the directories
you're trying to read... past that, it should work--the code looks fine.

DirectoryInfo dir = new DirectoryInfo(@"C:\");
DirectoryInfo[] dirs = dir.GetDirectories();

directoryInfo.DataSource = dirs;
directoryInfo.DataBind();

Then, on the ASPX side:

<asp:GridView ID="directoryInfo" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="FullName" HeaderText="Full Name" />
<asp:BoundField DataField="LastWriteTime" HeaderText="Last Write
Time" />
</Columns>
</asp:GridView>


Make sure your DataField matches the returned properties of the DirectoryInfo
object array. LastWriteTime is a property of the object... the binding is
above.

That output the GridView with:

C:\NVIDIA 3/12/2007 11:13:55 PM
C:\odp 6/18/2007 10:01:28 AM
C:\oracle 3/13/2007 2:04:11 PM
C:\RECYCLER 3/13/2007 2:53:39 PM
C:\sandbox 4/20/2007 3:05:03 PM
C:\System Volume Information 3/12/2007 8:43:10 PM
C:\test 6/18/2007 9:09:08 AM
C:\WINDOWS 6/29/2007 9:10:27 AM
....

etc.

HTH.

-dl

--
David R. Longnecker
http://blog.tiredstudent.com
Hi,

I need a way to bind a DirectoryInfo[] array to a GridView without
any errors.

The code I'm using to create the DirectoryInfo[] array is:

// Define the current directory
DirectoryInfo dir = new DirectoryInfo("C:\\Temp\\");
// Get the Directory info array
DirectoryInfo[] dirs = dir.GetDirectories();
This works fine, but everytime I try to bind it to the GridView I
get an error (something about LastWriteTime not found).

Can anybody help Please!!!

Thanks
Steve
Do you need that column?

<asp:GridView
AutoGenerateColumns="False"
...
<Columns>
<asp:BoundField DataField="Name"
HeaderText="Dir Name" />
</Columns>
</asp:GridView>- Hide quoted text -
- Show quoted text -
Thanks for writing. I have the AutoGenerateColumns="false" set
already.
Any other ideas?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top