Antonio,
It's hard to tell without knowing where the exception was thrown, but I
see two possibilities.
The first is the fi variable. Since all the filenames in a particular
directory are unique, you will have only one a.jpg. This means at max, you
will have a number of files equal to the number of sub directories. Because
of this, you will want to set fi to be the same length as the number of
directories that you have.
The second, and more likely situation is that the file a.jpg doesn't
exist in the directory, so the array of files returned has length zero,
which you are trying to access the first element of.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"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