I am saving my image files in the following format: 1-6784 (1 being the sort order that I want to see and 6784 being a randomly generated number between 1000 and 9999.
When I look at the folder through explorer and arrange by name they all look fine and sorted according to the first number i.e. (1-XXXX, 2-XXXX , 9-XXXX, 12-XXXX etc.) in ascending order.
However when I get the FileInfo array for this directory it automatically sorts it by name I presume, but it for some reason would place 10-XXXX and 11-XXXX before 1-XXXX, 2-XXXX etc. So up until 10 it's fine and the order retains when image src links are generated in the view in my web application, but once I upload\save more than 9 files the double digit 10, 11 etc. take front spots in the array over the single digit numbers.
DirectoryInfo sourceDir = new DirectoryInfo(System.Web.HttpContext.Current.Request.MapPath("~/Content/ProductImages/" + Model.Products[i].ProductID.ToString() + "/thumbs/"));
if (sourceDir.Exists)
{
FileInfo[] fileEntries = sourceDir.GetFiles();
Array.Sort(fileEntries, (f1, f2) => f1.Name.CompareTo(f2.Name));
}