473,506 Members | 13,088 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you bind a DirectoryInfo[] to a GridView

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
3 3078
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2131
by: COHENMARVIN | last post by:
I'm leafing through a big book on asp.net, and I don't see any way to the following: 1. bind values and text to a dropdown 2. Also make the first line of the dropdown say something different. For...
3
3321
by: Bob Lehmann | last post by:
Hi, I'm trying to bind an ArrayList to a DataList. I get the error DataBinder.Eval: 'System.String' does not contain a property with the name Name. I don't know what property of ArrayList...
2
4603
by: pittster | last post by:
Hi, I've bound a Gridview control to the GetFiles method Here is a code snippet: DirectoryInfo objDi = new DirectoryInfo(Server.MapPath("./somepath")); FileInfo arrFileInfo =...
4
29513
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor...
0
1696
by: teclioness | last post by:
Hi, I am using gridview for the user to update rows. In a row, there sre two columns, which need to be updated. When the gridview is to be shown, the row should show the values from database....
6
29160
by: Fao, Sean | last post by:
Is it possible to bind a GridView to a generic Dictionary object? When I try it in my ASP.NET application, it throws an exception acknowledging that the specified field or property does not exist....
0
2654
by: wardemon | last post by:
Hi All, I was just wondering if the following is possible? To bind a GridView's datasource to the Repeater's current DataRow value. I tried creating a dataset, then load the datarowview inside...
0
2165
by: GMartin | last post by:
I have a pop-up form with a three columned Grid that has checkboxes in a Template Column in the first/left-most column. (The form is to allow users to select "Members" of a group, where they check...
1
13891
by: dhamo | last post by:
How to bind checkbox with gridview in asp.net 2.0 I take a gridview control and bind data dynamicaly using code.I taken backend tool as a Ms Access and now I want to add new column with checkbox...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.