473,503 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 21 '05 #1
1 1342
Use the debugger to see what is getting returned from things like GetFiles.
There are only two places where this can be a problem, 1) the variable i is
larger then 999 or 2) the folder does not have the a.jpg file. I would say
single step through your code to determine what your code is doing. Make
sure you actually have an a.jpg in all the folders that you expect to
process. Maybe you can trap the exception and put a breakpoint in the catch
block to that you break into the code only when the error occurs.

"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

Jul 21 '05 #2

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

Similar topics

2
2578
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
1113
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
2917
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
1768
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
2499
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...
1
1492
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...
3
1516
by: Bala | last post by:
Hi From my aspx page i am calling one of the console.exe. that exe will copy the file from network to local webserver. everything hardcoded path. I given all the permission to that exe. I am...
10
5861
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
3740
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
2011
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
7199
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
7076
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
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
6984
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...
1
5005
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
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1507
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
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
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.