By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,954 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,954 IT Pros & Developers. It's quick & easy.

How do you bind a DirectoryInfo[] to a GridView

P: n/a
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

Jun 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jun 29, 12:01 am, Steve Kershaw <steve_kers...@yahoo.comwrote:
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>

Jun 28 '07 #2

P: n/a
On Jun 28, 4:09 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Jun 29, 12:01 am, Steve Kershaw <steve_kers...@yahoo.comwrote:


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?

Jun 28 '07 #3

P: n/a
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
On Jun 28, 4:09 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
>On Jun 29, 12:01 am, Steve Kershaw <steve_kers...@yahoo.comwrote:
>>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?


Jun 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.