Problem creating FileInfo Array

Discussion in 'ASP .Net' started by Antonio, Nov 23, 2004.

  1. Antonio

    Antonio Guest

    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
     
    Antonio, Nov 23, 2004
    #1
    1. Advertising

  2. I guess the problem is not in create FileInfo array. Its in
    dri.GetFiles("filename")[0]. Some directories might not have "a.jpg"
    file, and return a zero length FileInfo array. You need to check if
    length of the return array is greater than zero.
    Cheers!!

    Maqsood Ahmed
    Kolachi Advanced Technologies
    http://www.kolachi.net

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Maqsood Ahmed, Dec 17, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Do
    Replies:
    1
    Views:
    2,144
    srinivas moorthy
    Dec 1, 2003
  2. Craig Douglas

    Ordering FileInfo[] by date

    Craig Douglas, Jan 30, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    370
    Craig Douglas
    Jan 30, 2004
  3. Martin Dechev
    Replies:
    0
    Views:
    583
    Martin Dechev
    Apr 2, 2004
  4. =?Utf-8?B?U2VubmE=?=

    FileInfo from http

    =?Utf-8?B?U2VubmE=?=, Sep 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    472
    =?Utf-8?B?U2VubmE=?=
    Sep 13, 2004
  5. Antonio

    Problem creating FileInfo Array

    Antonio, Nov 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    457
    Dan Bass
    Nov 23, 2004
Loading...

Share This Page