473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Problem creating FileInfo Array

Good morning,
I've the following file system :

C: -> HTML -> Aziende -> Azienda_1 -> a.jpg
-> Azienda_2 -> a.jpg
...
-> Azienda_N -> a.jpg

my desire is to create an array of fileinfo containing the a.jpg ,
a.jpg , ... , a.jpg
in a way that I could bind this to a datagrid to show some properties
of these files.
I tried the following but it is not ok

FileInfo[] fi ;
DirectoryInfo dirInfo = new DirectoryInfo("C:\HTML\Aziende");
DirectoryInfo[] di = dirInfo.GetDirectories();
int i = 0;
fi = new FileInfo[1000];
foreach (DirectoryInfo dri in di)
{
fi[i++] = dri.GetFiles("a.jpg")[0];
}

the error is System.IndexOutOfRangeException
could you help me to solve this problem and to crate the array of
FileInfo types ??

Thanks ...
Antonio
Nov 18 '05 #1
1 1484
rather than FileInfo[] fi, use ArrayList or another collection object. They
are dynamic and can grow the more objects you have, and can hold any object
type (FileInfo included)...

ArrayList fi = new ArrayList();
string fileName = "a.jpg";

foreach ( DirectoryInfo dri in di )
{
if ( dri.GetFiles(fileName).Count > 0 )
{
fi.Add ( dri.GetFiles(fileName)[0] );
}
}


"Antonio" <et*******@libero.it> wrote in message
news:ba**************************@posting.google.c om...
Good morning,
I've the following file system :

C: -> HTML -> Aziende -> Azienda_1 -> a.jpg
-> Azienda_2 -> a.jpg
...
-> Azienda_N -> a.jpg

my desire is to create an array of fileinfo containing the a.jpg ,
a.jpg , ... , a.jpg
in a way that I could bind this to a datagrid to show some properties
of these files.
I tried the following but it is not ok

FileInfo[] fi ;
DirectoryInfo dirInfo = new DirectoryInfo("C:\HTML\Aziende");
DirectoryInfo[] di = dirInfo.GetDirectories();
int i = 0;
fi = new FileInfo[1000];
foreach (DirectoryInfo dri in di)
{
fi[i++] = dri.GetFiles("a.jpg")[0];
}

the error is System.IndexOutOfRangeException
could you help me to solve this problem and to crate the array of
FileInfo types ??

Thanks ...
Antonio

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dariusz | last post by:
I have a problem where when I run the PHP code offline, there are no errors produced and the code runs as expected. However when I uploaded the same script and run it, it says the headers have...
5
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up...
1
by: Lentdave67t | last post by:
Thank you in advance for any help you can provide. I am writing a C# program that checks to see if the URLs of favorites/bookmarks are still good. The problem I am having is that while the...
2
by: Lentdave67t | last post by:
Thank you in advance for any help you can provide. I am writing a C# program that checks to see if the URLs of favorites/bookmarks are still good. The problem I am having is that while the...
1
by: Antonio | last post by:
Good morning, I've the following file system : C: -> HTML -> Aziende -> Azienda_1 -> a.jpg -> Azienda_2 -> a.jpg ... -> Azienda_N -> a.jpg my desire is to create an array of fileinfo...
2
by: John Bowman | last post by:
Hi All, ..NET 1.1... I'm wondering if there is any approach more convenient to get a list of FileInfo objects than the following. For example, if I wanted to get 1 list of all the Exe's and all...
10
by: Michael Murphy | last post by:
Hi, I have a Windows VB.Net app in which I need to keep files in one folder in sync with files in another folder. I have pasted the code below. Can anyone tell me why I end up with a folder with all...
5
by: Robbert van Geldrop | last post by:
Hello, I have a problem consuming a WebService which appears to be dependent of the type of network I am on: The following SOAP response is not processed when I am connected over the internet...
0
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.