Link to home
Start Free TrialLog in
Avatar of cay187
cay187

asked on

arraylist images from directory sorting by filename

I am using c# with asp.net to fill an arraylist with images (jpg) that are in a directory.  i am using the filesystem to upload images to a directory and i am renaming them with a date_time stamp as the file name.  ie  
03202009_10_22_13_pm.jpg
03122009_11_29_05_am.jpg
03312009_1_15_45_pm.jpg
how can i display the arraylist in a datalist sorting by FILE NAME?


if (Directory.Exists(Server.MapPath(strPath)))
        {
            DirectoryInfo dirInfoImages = new DirectoryInfo(Server.MapPath(strPath));
            ArrayList listImages = new ArrayList();
            listImages.AddRange(dirInfoImages.GetFiles("*.jpg"));
            listImages.AddRange(dirInfoImages.GetFiles("*.jpeg"));                        
            DL_Images.DataSource = listImages;
            DL_Images.DataBind();            
        }

Open in new window

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

What version C# you working with?
Avatar of cay187
cay187

ASKER

.net 3.5
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cay187

ASKER

List<FileInfo> listImages = new List<FileInfo>();
you are way more advanced at arrays than i am.  you suggest i replace
ArrayList listImages = new ArrayList();
with
List<FileInfo> listImages = new List<FileInfo>();?
what is<FileInfo>?
The List is basically a TYPE-SAFE, dynamic array.  The <FileInfo> part is telling it what Type of data will be in the list.
See Generic List: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

An ArrayList is a dynamic list that accepts anything because it takes Object.  So you were actually placing FileInfo instances into your ArrayList with your old code because DirectoryInfo.GetFiles() returns an Array of FileInfo.
See DirectoryInfo.GetFiles(): http://msdn.microsoft.com/en-us/library/8he88b63.aspx

Avatar of cay187

ASKER

i will try this today
Avatar of cay187

ASKER

That did it.  Thank you very much!!