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?
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();
}
What version C# you working with?
ASKER
.net 3.5
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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>?
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
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
ASKER
i will try this today
ASKER
That did it. Thank you very much!!