I am creating Image Gallery and I am unable to sort the image files according to published date format. I have a model class of ImageGallery. How to get the files in sorted format?

public class ImageGallery
    {
        public ImageGallery()
        {
            ImageList = new List<string>();
        }
        [Key]
        public Guid ID { get; set; }
        public string Name { get; set; }
        public string ImagePath { get; set; }
        public List<string> ImageList { get; set; }

        public DateTime PublishedDate { get; set; }
    }

and Controller action

public ActionResult Gallery()
        {
            var imagesModel = new ImageGallery();
            var imageFiles = Directory.GetFiles(Server.MapPath("/Gallery/"));
            foreach (var item in imageFiles)
            {
                imagesModel.ImageList.Add(Path.GetFileName(item));
            }


            return View(imagesModel);
        }

and View of Gallery

<div>
    @if (Model.ImageList.Count > 0)
    {
        <div class="row-fluid">
            <div class="span2">
                <div class="item">
                    @foreach (var image in Model.ImageList)
                    {
                        <div>
                            <a href="@Url.Content("~/Gallery/"+ image)"><img src="@Url.Content("~/Gallery/" + image)" alt="" /></a>


                        </div>
                    }
                </div>
            </div>
        </div>
    }
</div>

Related posts

Recent Viewed